Reputation: 15378
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>
Upvotes: 0
Views: 115
Reputation: 1039468
After you submit look at the desk.ID
property => it will be assigned the new value from the database.
Upvotes: 3