日期:2014-05-20  浏览次数:20845 次

SQL语句转换成LINQ怎么写
select *,
(select CollectData from LastestData z1 where z1.DeviceMonitorObjectID=b.DeviceMonitorObjectID and z1.DeviceMonitorObjectID='215764AC-F19D-43B2-B942-8F0E5669EEBF') '水',
(select CollectData from LastestData z1 where z1.DeviceMonitorObjectID=b.DeviceMonitorObjectID and z1.DeviceMonitorObjectID='215764AC-F19D-43B2-B942-8F0E5669EEBF') '电'
from dbo.EnterpriseSiteDevice a
inner join dbo.DeviceMonitorObject b
on a.EnterpriseSiteDeviceID=b.EnterpriseSiteDeviceID


对于LINQ刚刚入门 现在遇到这么个语句 很是头疼  希望前辈们帮下忙  这段SQL如果用LINQ该怎么写啊
------最佳解决方案--------------------

//没看出你的水电查询条件不什么不一样...
var query=from a in dbo.EnterpriseSiteDevice
          join b in dbo.DeviceMonitorObject 
          on a.EnterpriseSiteDeviceID equals b.EnterpriseSiteDeviceID
          select new 
          {
              a,
      b,
              水=LastestData.Where(z1=>z1.DeviceMonitorObjectID == b.DeviceMonitorObjectID && z1.DeviceMonitorObjectID =="215764AC-F19D-43B2-B942-8F0E5669EEBF").Select(z1=>z1.CollectData),
             电=LastestData.Where(z1=>z1.DeviceMonitorObjectID == b.DeviceMonitorObjectID && z1.DeviceMonitorObjectID =="215764AC-F19D-43B2-B942-8F0E5669EEBF").Select(z1=>z1.CollectData)
          };


------其他解决方案--------------------
引用:
select *,
(select CollectData from LastestData z1 where z1.DeviceMonitorObjectID=b.DeviceMonitorObjectID and z1.DeviceMonitorObjectID='215764AC-F19D-43B2-B942-8F0E5669EEBF') '水',
(select CollectData……

多谢督查的帮助  看了以后很有启发
水、电随便写的 用来试试看能不能从表里取出数据的
再次感谢~