如何扩展实体框架生成的实体,但不将其映射到数据库列

时间:2014-09-17 12:43:26

标签: c# entity-framework

我的情况是: 1.我有EF通过模型设计师生成的实体模型。 数据库也是由EF通过模型设计者生成的。 2.所有实体'属性分别映射到DB列。    对于例如我生成的"有问题的"实体是:

[EdmEntityTypeAttribute(NamespaceName="MyModel", Name="File")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class File : ContentItem
{
    //some properties

    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int32 Major
    {
        // get and set are here
    }

    //another properties
}

我需要: 1.使用一个标量属性手动扩展实体(在生成的同一命名空间中创建部分类);    我做了什么:

public partial class File
{
    [DataMemberAttribute()]
    public double ContextWeight { get; set; }
}
  1. 这个新的" ContextWeight"当服务执行特定功能时,将计算并初始化属性。然后我需要在客户端(代理)上提供此属性。
  2. 问题: 当我构建服务项目然后在客户端(代理)项目中更新服务引用时,那么在客户端(代理)上我不会看到File类中存在的这个新属性。

    注意:我不需要" ContextWeight"属性映射到任何数据库列。

    你能告诉我应该添加什么(可能缺少某些属性或其他什么)?

0 个答案:

没有答案