I have many Accounts
, each account can also have child accounts. So my way of knowing if an account is root is thanks to the value in the ParentId
property.
So it turned out that my code has stuff like this in many places: .Where(acc => acc.ParentId == 0)
so I thought about creating a property that looks like this:
public bool IsRootAccount
{
return a.ParentId == 0;
}
It seems to work, it compiles, but when running I get the following exception:
Load operation failed for query 'GetAccounts'. The specified type member 'IsRootAccount' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Is there a simple way I can achieve what I want?
I also thought about creating something that would return an Expression<Func<Account, bool>>
with no luck.
Edit: my attempt for the IsRootAccount
property was in order to use something like this .Where(acc => acc.IsRootAccount)