Update Model From Database... in Entity Framework - no update!

.net entity-framework updatemodel

Question

In my database, I have a table namedCompanyDetails It includes a column titledCharacterID varchar(255) . It was a merely modified from aNOT NULL a column toNULL column. I executed the 'Update Model From Database...' command both in the EDMX file reader and the model browser. It produced the following in the designer:

/// <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();

You'll see that it has the following quality:

[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(IsNullable=false)]

I also added the following property, which is appropriately labelled as follows:

[global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]

How come? How can I actually get the Entity Framework to update depending on little changes I make to my database schema? Every time there was a change, I had to abandon and start again with the model.

1
14
2/2/2010 11:44:21 PM

Accepted Answer

The database system and mapping are specified by the entity framework using an XML file called the edmx. This edmx file is updated when you choose "update model from database."

If you want to see the change reflected in the underlying classes, you must first update the model and then recompile your app since this edmx file is parsed and created when you build your app.

Finally, keep in mind that the edmx consists of three components.

  1. The database and storage plan (SSDL)
  2. The theoretical model (CSDL)
  3. The relation between storage and conceptual (MSL)

Although updating the database and selecting "update" will update the SSDL, it may be necessary to access the designer's edmx file and examine the field's properties before the conceptual model is updated as needed. (It is perfectly feasible, but clearly not what you want in this situation, to have a nullable database column mapped to a non-nullable conceptual field.)

18
2/3/2010 12:21:39 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow