LINQ to Entities 如何对字段进行子查询
为了保存多个数据库调用,并且由于它来自同一个表,我正在查找 linq 查询中的字段之一以返回具有 2 个 IEnumerable 字段的对象。
我在这里写了一些伪代码来说明我想要做什么,但它不是有效的 Linq 代码。有人知道如何进行这项工作吗? (Fred 和 Joe 都是 IEnumerable)
var c = from jobs in model.jobView
select jobs.JobID, jobs.NameID, new
{
Fred = from j in model.jobView
select jobs.Field1,
Joe = from k in model.jobView
select jobs.Field2
};
To save multiple DB calls, and since it is from the same table, I'm looking for one of the fields in my linq query to return an object with 2 fields that are IEnumerable.
I wrote some pseudeocode here that should illustrate what I'm trying to do, but its not valid Linq code. Anyone know how to make this work? (Fred & Joe will both be IEnumerable)
var c = from jobs in model.jobView
select jobs.JobID, jobs.NameID, new
{
Fred = from j in model.jobView
select jobs.Field1,
Joe = from k in model.jobView
select jobs.Field2
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要创建一个匿名类型,然后在其中创建另一个匿名类型。
我猜您的两个集合中有一个拼写错误,您使用了
j
和k
,但选择了jobs
You want to create an anonymous type and then create another anonymous type within it.
I am guessing there is a typo in your two collections where you use
j
andk
, but select withjobs