我已经阅读了here和here,但我仍然无法理解为什么我会收到此错误。 c.NvrId和n.Id都是int
var cameras = from c in context.CameraEntities
join n in context.NetworkVideoRecorderEntities
on c.NvrId equals n.Id
into cn
from x in cn.DefaultIfEmpty()
where listofIds.Contains(c.Id)
select new Camera
{
Id = c.Id,
Name = c.Name,
NetworkVideoRecorder = cn == null ? null : new NetworkVideoRecorder
{
Id = x.Id,
Description = x.Description,
IP = x.IP,
}
};
return cameras.ToList();
执行cameras.ToList();
这是完整的错误消息:
Cannot compare elements of type 'System.Collections.Generic.IEnumerable`1[[Models.NetworkVideoRecorderEntity, Asis.Ibss.Net.DataObjects, Version=2014.1.5494.33354, Culture=neutral, PublicKeyToken=null]]'. Only primitive types, enumeration types and entity types are supported.
答案 0 :(得分:0)
您正在'select'子句中进行空检查。
NetworkVideoRecorder = cn == null ? null : new NetworkVideoRecorder { Id = x.Id, Description = x.Description, IP = x.IP, }
正如@RahulSingh在评论中指出的那样,我认为你最好检查x是否为null而不是检查cn是否为空。