我有很多Accounts
,每个帐户也可以有子帐户。因此,我知道一个帐户是否为root的方式归功于ParentId
属性中的值。
所以,事实证明,我的代码有这样的东西在很多地方:.Where(acc => acc.ParentId == 0)
所以我认为有关创建看起来像这样的属性:简化此属性以用于谓词
public bool IsRootAccount
{
return a.ParentId == 0;
}
看来工作,它编译,但在运行时我得到但以下情况除外:
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.
有一个简单的方法可以让我实现我想要什么?
我也想过创造一些东西,会返回一个没有运气的Expression<Func<Account, bool>>
。
编辑:我为IsRootAccount
财产尝试是为了使用这样的.Where(acc => acc.IsRootAccount)
“IsRootAccount”的返回类型与返回的值('bool'!= lambda)不匹配。 – 2012-03-09 00:17:51
谢谢,我解决了它...我从一个不同的属性复制:) – sebagomez 2012-03-09 00:26:14
你也可以告诉我们你试图建立的查询消耗这个属性?我怀疑你可以做到你想要的东西,但我们可能会提出一些替代解决方案。 – 2012-03-09 00:31:49