我有一个实体框架模型(v.1.0),我试图扩展一个计算属性。实体框架计算属性问题
我创建了部分类以这种方式扩大实体对象“要约”:
namespace MyModelNamespace
{
public partial class Offer
{
public bool MyProperty
{
get
{
// my stuffs the return true or false
}
}
}
}
它编译没有在我的装配问题,但在运行时,当我试图做一些事情像这样:
_myEntities.OfferSet.FirstOrDefault(o=>o.MyProperty);
我找回这个错误:
The number of members in the conceptual type 'MyModelNamespace.Offer' does not match with the number of members on the object side type 'MyModelNamespace.Offer'. Make sure the number of members are the same.
...任何建议???
有趣...我会尽快尝试! – tanathos 2010-07-29 23:27:39
我正在尝试它,但我无法得到它的工作:(......我已经包括了DLL,它编译得很好,但在运行时我得到像这样:“指定的成员'MyProperty'不支持LINQ to Entities“我完全按照你发布的链接中的例子 – tanathos 2010-07-30 08:10:15
@tanathos你的问题可能与静态初始化有关。请参阅Matyas Boros在8月30日关于该文章的评论。建议的解决方法是在类上创建一个(空)静态构造函数,然后在查询对象之前有时实例化该对象的一个实例。丑陋:( – AaronSieb 2011-01-12 22:28:37