I am wondering how to create a property that can be translated by LINQ. Below is a very simple example.
I have a Category
table / class that has a ParentId
column associated with itself (so the category may have subcategories)
EF automatically generates the Category1
property, which is the parent category.
For clarity, I created another property.
public partial class Category { public Category Parent { get { return Category1; } } }
The problem is that it works
var categs = ctx.Categories.Where(x => x.Category1 == null);
but it does not work
var categs = ctx.Categories.Where(x => x.Parent == null);
The specified Parent member is not supported in LINQ to Entities. Only initializers, entities, and entity navigation properties are supported.
Is there a way to create a translatable (LINQ to SQL) property without executing .ToList ()?
EDIT: I want to avoid touching Model.edmx because the database often changes during development, and .edmx often needs to be recreated
source share