首页 > 其他 > 详细

Linq 多个实体Group by

时间:2016-03-05 18:43:18      阅读:257      评论:0      收藏:0      [点我收藏+]

自产自销,不喜欢匆喷

解决思路,搞不定的地方就用new 加{}

 

demo

using (var db = DbServices.GetDbProvider())
{
IQueryable<AreaPropertyLogEntity> queryAreaProperty = db.GetQuery<AreaPropertyLogEntity>();
IQueryable<TransferEntity> queryTransfer = db.GetQuery<TransferEntity>();
var query = (from areaPropery in queryAreaProperty
join transfer in queryTransfer on areaPropery.TransferCode equals transfer.TransferCode
where areaPropery.PropId == propId
group new { transfer, areaPropery }
by new
{
ID = areaPropery.ID,
TransferCode = transfer.TransferName,
AreaCode = areaPropery.AreaCode,
AreaName = areaPropery.AreaName,
CanCOD = areaPropery.CanCOD,
CanMovePos = areaPropery.CanMovePos,
CanCWO = areaPropery.CanCWO,
SchemeCode = areaPropery.SchemeCode,
CreateTime = areaPropery.CreateTime,
Creator = areaPropery.Creator,
CreatorID = areaPropery.CreatorID
}

into g
select new AreaPropertyLogEntity
{
ID = g.Key.ID,
TransferCode = g.Key.TransferCode,
AreaCode = g.Key.AreaCode,
AreaName = g.Key.AreaName,
CanCOD = g.Key.CanCOD,
CanMovePos = g.Key.CanMovePos,
CanCWO = g.Key.CanCWO,
SchemeCode = g.Key.SchemeCode,
CreateTime = g.Key.CreateTime,
Creator = g.Key.Creator,
CreatorID = g.Key.CreatorID
}


).ToList();
}

Linq 多个实体Group by

原文:http://www.cnblogs.com/seanlau/p/5245327.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!