lambda SQL MSSql执行这段没问题。MYSql执行出问题。
备注:2表左连接 (A.F_Id equals B.F_PortId ) 关系是1对多 但是查询出来的数据是:A.F_Id equals B.F_PortId 最新的一条数据。假如:A 表有一条数据 A.F_Id =0; B表有10条数据:0 XX,0 X1 ,0 X2 ... ... 那么根据创建时间排序找出最新的一条记录。
当然也有可能B表是空数据。
求:大神指点一二。嘿嘿 。 (此处应该有笑脸)但是CSDN居然不能输入笑脸。。。。。。。
var result = (from A in sl_portcode.Select(a => new { a.F_Id, a.F_LocationNumber, a.F_LayerNumber, a.F_Code, a.F_GroupId })
join B in sl_portlog on A.F_Id equals B.F_PortId into H
from X1 in H.DefaultIfEmpty().Select(a => new { a.F_InTime, a.F_OutTime, a.F_CreatorTime }).OrderByDescending(a => a.F_CreatorTime).Take(1)
select new StorageLayout
{
F_Id = A.F_Id,
X = A.F_LocationNumber.Value,
Y = A.F_LayerNumber.Value,
F_Code = A.F_Code,
F_GroupId = A.F_GroupId,
F_Color = (X1==null?"": X1.F_InTime != null && X1.F_OutTime == null ? "yellow" : (X1.F_InTime != null && X1.F_OutTime != null) ? "blue" : null)
(X1.F_InTime != null && X1.F_OutTime == null ? "yellow" : (X1.F_InTime != null && X1.F_OutTime != null) ? "blue" : null)
}).OrderByDescending(a => a.F_GroupId).Where(u => listsss.Contains(u.F_GroupId));