Linq to Entities - 使用实体集加入列表

时间:2013-01-03 08:41:33

标签: c# linq entity-framework linq-to-entities anonymous-types

我可以使用listname.Join()方法将实体集加入列表(集合)。

例如,

var query = listName.Join(repository.GetQuery<MyCustomType>(),
 list => list.CustomTypeId,
 customType => customType.id,
 (list, customType) => list); 

这样可以正常工作,但它只返回与实体中列表集合相关的行。我还想在结果集中使用“MyCustomType”的实例。我如何实现这一目标?

1 个答案:

答案 0 :(得分:2)

var query = listName.Join(repository.GetQuery<MyCustomType>(),
 list => list.CustomTypeId,
 customType => customType.id,
 (list, customType) => new { l = list, c = customType } );