实体框架 - 从数据库更新模型... - 没有更新发生!

Kei*_*ows 14 .net entity-framework updatemodel

我的数据库中有一个表叫做CompanyDetails.它有一个名为的列CharacterID varchar(255).我只是将它从NOT NULL列更改为NULL列.我在模型浏览器和EDMX文件查看器中运行了"从数据库更新模型..."命令.这就是它在设计师中创造的内容:

/// <summary>
/// There are no comments for Property CharacterId in the schema.
/// </summary>
[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(IsNullable=false)]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public string CharacterId
{
    get
    {
        return this._CharacterId;
    }
    set
    {
        this.OnCharacterIdChanging(value);
        this.ReportPropertyChanging("CharacterId");
        this._CharacterId = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, false);
        this.ReportPropertyChanged("CharacterId");
        this.OnCharacterIdChanged();
    }
}
private string _CharacterId;
partial void OnCharacterIdChanging(string value);
partial void OnCharacterIdChanged();
/// <summary>
/// There are no comments for Property URLDomain in the schema.
/// </summary>
[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public string URLDomain
{
    get
    {
        return this._URLDomain;
    }
    set
    {
        this.OnURLDomainChanging(value);
        this.ReportPropertyChanging("URLDomain");
        this._URLDomain = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);
        this.ReportPropertyChanged("URLDomain");
        this.OnURLDomainChanged();
    }
}
private string _URLDomain;
partial void OnURLDomainChanging(string value);
partial void OnURLDomainChanged();
Run Code Online (Sandbox Code Playgroud)

您会注意到它具有以下属性:

[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(IsNullable=false)]
Run Code Online (Sandbox Code Playgroud)

我还包括下一个属性,你会注意到它被正确标记为:

[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
Run Code Online (Sandbox Code Playgroud)

是什么赋予了?如何在我的数据库模式中进行简单的更改,并根据这些更改真正获得要更新的实体框架?!每次发生变化时,我都不得不放弃并重新创建模型!

Sim*_*ens 18

实体框架使用XML文件(edmx)来指定数据库方案和映射.单击"从数据库更新模型"时,将更新此edmx文件.

接下来,在编译应用程序时,将解析此edmx文件并生成您正在查看的支持类,因此,如果要查看支持类中反映的更改,则需要更新模型,然后重新编译.

最后,您还必须记住edmx包含3件事.

  1. 数据库/存储方案(SSDL)
  2. 概念模型(CSDL)
  3. 概念和存储(MSL)之间的映射

更新数据库并单击"更新"将更新SSDL,但不一定会自动对概念模型进行必要的更改,您可能需要打开edmx是设计器并检查字段上的属性.(完全可以将可空的数据库字段映射到不可为空的概念字段,但显然在这种情况下不是您想要的).

  • 谢谢克雷格.另外请注意,我相信你可以使用工具edmgen(http://msdn.microsoft.com/en-us/library/bb387165.aspx)与开关/模式:FromSSDLGeneration或/ mode:FullGeneration来强制生成CSDL + MSL或所有块,如果这是你需要的. (4认同)