Reputation: 11360
I've read here and here, but I still can't figure why I'm getting this error. both c.NvrId and n.Id are of type 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();
Error gets thrown when I perform a cameras.ToList();
This is the full error message:
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.
Upvotes: 1
Views: 4138
Reputation: 2585
You were doing a null check within the 'select' clause.
NetworkVideoRecorder = cn == null ? null : new NetworkVideoRecorder { Id = x.Id, Description = x.Description, IP = x.IP, }
As @RahulSingh pointed out in the comments, I think you are better off checking if x is null rather than checking if cn is null.
Upvotes: 1