![](/img/trans.png)
[英]Best practice for updating related entities in ASP.NET MVC + EF4 without loading entity first
[英]LINQ - Join Two Entities into One IQueryable Complex Type - EF4 and ASP.Net MVC
我有这样的代码:
var entityX = this._xService.GetAll();
var entityY = this._yService.GetAll();
两者都作为IEnumerable类型返回。 我需要将两者内部连接成类似JoinedList类的类,该类必须是IQueryable。
我正在寻找使用LINQ的方法。
非常感谢
LINQ to Objects是出色的粘合剂:
var entityX = this._xService.GetAll();
var entityY = this._yService.GetAll();
var joinedSequence = from x in entityX
join y in entityY on x.Key equals y.Key
select new { x, y };
var joinedQueryable = joinedSequence.AsQueryable();
您实际上不需要最后一步; IQueryable<T>
是不必要的,因为LINQ to Objects与IEnumerable<T>
可以很好地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.