I have written this code
IQueryable sites = context.MainTable.Include(\"RelatedTable\");
if (!string.IsNullOrEmpty(param1)) {
sites = sites.
Collection field can be null in this case you get exception NullReferenceException
when use RelatedTables.Any()
If you add RelatedTables != null as in a question then you can get
Cannot compare elements of type 'System.Collections.Generic.ICollection`1[[Project1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. Only primitive types, enumeration types and entity types are supported.
If you get the NullReferenceException exception, lazy loading is not turned off and you are good with lazy loading for the field then to prevent exception mark field with virtual keyword to allow lazy loading for the field
virtual ICollection RelatedTables{ get; set; }
- 热议问题