wcf数据服务-如何扩展dbcontext实体类



我已经通过WCF数据服务公开了一些从数据库生成的EF5.0实体。

数据服务由WPF客户端使用,该客户端获取实体(来自数据服务)并将其存储在本地。我通过创建一个基于WCF实体的代码优先实体数据库来做到这一点:

public class LocalRaceContext : DbContext
{
    public LocalRaceContext() { }
    public LocalRaceContext(string connstr) : base(connstr) { }
    public DbSet<Participant> Participants { get; set; }
    .
    .
    . more ...
}

我想用一个新的属性(在客户端模型中)来扩展Participant。我想我可以用这样一个偏类来做这件事:

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版:我试图创建一个空的分部类(没有属性)。它仍然抛出相同的错误。

提前感谢

弗雷德里克

EF还不支持嵌套类。将Participant类移到RaceEntity之外。

最新更新