我已经公开了一些通过WCF数据服务从数据库生成的EF5.0实体。如何扩展一个dbcontext实体类?
数据服务由WPF客户端使用,该客户端将实体(来自数据服务)并将其存储在本地。我这样做,通过创建基于WCF的实体代码优先实体数据库:
public class LocalRaceContext : DbContext
{
public LocalRaceContext() { }
public LocalRaceContext(string connstr) : base(connstr) { }
public DbSet<Participant> Participants { get; set; }
.
.
. more ...
}
我想延长一个新的属性(在客户端模式)的参与者。我想我可以用这样的部分类来做到这一点:
public partial class Participant
{
public virtual List<Stamp> Stamps { get; set; }
}
但是,这是行不通的。我是否需要部分类的某种属性?
我收到以下错误:
"The type 'RaceEntities+Participant' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject."
编辑:
@ IronMan84:最初的型号(不带局部类)的作品,因为EF代码优先采用数据库和表的护理创建。事实上,它工作得很好,我能够将EF模型保存在本地SQL CE文件中,并在以后再次以EF类的形式检索对象。
我想要实现的是将数据从本地数据服务中持久化,但在一个稍微扩展的模型中。到目前为止,我已经成功地完成了扩展部分。
@Matt Whetton:创建LocalRaceContext的新实例时失败。
编辑2:我试图做出一个空的部分类(没有属性)。它仍然会抛出同样的错误。
在此先感谢
弗雷德里克
什么时候失败? – 2013-02-21 13:33:54
你想添加这个*客户端模型*?当然,这不会起作用。您的数据库模型不知道该字段是什么。你想做什么? – IronMan84 2013-02-21 14:34:19
我编辑了我的问题 - 包括您的意见回答 – Frederik 2013-02-21 17:00:40