public RoomClean RoomCleanDateTest2(int id)
{
RoomClean rcc = new RoomClean();
var left = (from rc in db.RoomCleans
join rsr in db.RoomStatusRecords
on rc.StatusID equals rsr.StatusID
into all
from rs in all.DefaultIfEmpty()
where rc.CleanID == id
select new
{
RoomID = rc.RoomID,
StatusID = rc.StatusID
}
).FirstOrDefault();
return rcc ;
}
====================================
如何返回RoomClean的类型呢?我试过强制转换的方式不可取
你select new RoomClean{RoomID = rc.RoomID,StatusID = rc.StatusID }这样
不要new{},就可以啦
RoomClean 如果是生成的映射实体类在LINQ TO SQL情况你这样会异常的,楼主不嫌麻烦可以先ToArrary()或ToList(),再投射一次。(ToArray().Select(c=> new RoomClean{RoomID = c.RoomID,StatusID = c.StatusID }))注意,前面的select也保留,不然所有字段都会在内存中。
我一般都用的这个类型dynamic去接收的。都不用转换的。视图上直接用。
你做映射了呀 .映射的时候直接c=>new RoomClean{RoomID = rc.RoomID,
StatusID = rc.StatusID}