0

I insert object to List and save.

Table Desk(int auto incriment ID, varchar NAME)

var desk = new Desk()
           {
           name = "newName"
           };

m_RoomsContext.Desks.Add(desk);
m_RoomsContext.SubmitChanges();

//desk.id == 0

I need get id the desk. How to do this?

property id:

/// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int32 id
    {
        get
        {
            return _id;
        }
        set
        {
            if (_id != value)
            {
                OnidChanging(value);
                ReportPropertyChanging("id");
                _id = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("id");
                OnidChanged();
            }
        }
    }
    private global::System.Int32 _id;
    partial void OnidChanging(global::System.Int32 value);
    partial void OnidChanged();

edmx:

 <EntityType Name="Desk">
          <Key>
            <PropertyRef Name="id" />
          </Key>
          <Property Name="id" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="width" Type="float" Nullable="false" />
          <Property Name="height" Type="float" Nullable="false" />
          <Property Name="x" Type="int" Nullable="false" />
          <Property Name="y" Type="int" Nullable="false" />
          <Property Name="countMax" Type="int" Nullable="false" />
          <Property Name="countReal" Type="int" />
          <Property Name="date" Type="datetime" />
          <Property Name="id_status" Type="int" Nullable="false" />
        </EntityType>
2
  • Is Id in your entity model defined with StoreGeneratedPattern.Identity (check properties of Id property in EDMX file)? Commented Jun 12, 2011 at 10:30
  • I update post. no StoreGeneratedPattern.Identity exist. Commented Jun 12, 2011 at 11:00

1 Answer 1

3

After you submit look at the desk.ID property => it will be assigned the new value from the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.