Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group by 查询多个表提示Value cannot be null #257

Open
wodemingzijiaoke opened this issue Oct 25, 2023 · 8 comments
Open

group by 查询多个表提示Value cannot be null #257

wodemingzijiaoke opened this issue Oct 25, 2023 · 8 comments

Comments

@wodemingzijiaoke
Copy link

使用query.select(q=> q.time).groupby(g=> g).count() Linq报错, Value cannot be null。查询的表有的是没有数据的。但是查单个表是不会报这个错的

@xuejmnet
Copy link
Collaborator

xuejmnet commented Oct 25, 2023

query.groupby(g=> g.time).select(q=> new{time=q.Key}).count() 试试这种写法呢,你的问题我这几天看看

@xuejmnet
Copy link
Collaborator

当然这边也建议你用distinct来代替呢,比如query.select(q=> q.time).distinct().count()

@xuejmnet
Copy link
Collaborator

xuejmnet commented Oct 25, 2023

group的限制是查询的结果必须包含group时候的key,所以先group后select是满足这个情况的,包括tolist这种需要先select后orderby而不是先orderby后select

@wodemingzijiaoke
Copy link
Author

query.groupby(g=> g.time).select(q=> new{time=q.Key}).count() 这种写法也试过,会报错:[Key] not in type:[Table]
query.select(q=> q.time).distinct().count() 这个会报错
query.select(q=> new { q.time}).distinct().count() 这个是可以的

@xuejmnet
Copy link
Collaborator

@wodemingzijiaoke 实在不好意思因为分片+group是一种比较复杂的聚合处理,如果您不涉及分库那么可以使用shardingcore的unionmerge 具体代码参考 https://github.com/dotnetcore/sharding-core/tree/main/samples/Sample.SqlServer

@wodemingzijiaoke
Copy link
Author

好的,我去试下

@wodemingzijiaoke
Copy link
Author

我用的是mysql8,我在mysql的demo中没有找到关于unionmerge的用法,可以提供下demo吗

@xuejmnet
Copy link
Collaborator

我用的是mysql8,我在mysql的demo中没有找到关于unionmerge的用法,可以提供下demo吗

和sqlserver处理一样就换一下对应的方言生成器就好了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants