LINQ to Entities 中的动态获取?
假设我有以下表格:
Category: ID, Name, Limit
News: ID, Title
Relation: CID, NID
我想从带有 CID、CName 的新闻表中选择热门“x”新闻,并且“x”取决于 Category.Limit。例如
Category
ID Name Limit
1 A 2
2 B 3
News
ID Title
1 News 1
2 News 2
3 News 3
4 News 4
Relation
CID NID
1 1
1 2
1 3
2 4
2 3
2 2
2 1
,那么我们将得到结果:
CID CName NID NTitle
1 A 1 News 1
1 A 2 News 2
2 B 4 News 4
2 B 3 News 3
2 B 2 News 2
是否可以仅使用 1 个 linq 查询来获得结果?如果不是那么存储过程?
任何帮助将不胜感激!
Let say I have the following tables:
Category: ID, Name, Limit
News: ID, Title
Relation: CID, NID
I want to select top 'x' news from News table with CID, CName and that 'x' depends on Category.Limit. For e.g
Category
ID Name Limit
1 A 2
2 B 3
News
ID Title
1 News 1
2 News 2
3 News 3
4 News 4
Relation
CID NID
1 1
1 2
1 3
2 4
2 3
2 2
2 1
Then we will have the result:
CID CName NID NTitle
1 A 1 News 1
1 A 2 News 2
2 B 4 News 4
2 B 3 News 3
2 B 2 News 2
Is it possible to achieve the result with only 1 linq query? If not then a store procedure?
Any helps would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,对于每个类别,您都希望拥有第一个
x
新闻,其中x
是该类别的限制。此答案假设
Category
实体包含导航属性News
,其中包含属于某个类别的所有新闻。If I understand you correctly, for each category, you want to have the first
x
news, wherex
is the limit of that category.This answer assumes that the
Category
entity contains a navigation propertyNews
that contains all news that belong to a category.