2011-06-12 4 views
0

개체를 목록에 삽입하고 저장하십시오.엔티티 업데이트 방법

표 데스크 (INT 자동 incriment의 ID, VARCHAR 명)

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

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

//desk.id == 0

나는 ID에게 책상을받을 필요가있다. 이 작업을 수행하는 방법?

속성 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 : 당신이 desk.ID 숙박 시설에서 모습을 제출하면

<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> 
+0

엔티티 모델에서 'StoreGeneratedPattern.Identity' (EDMX 파일의'Id' 속성의 속성 확인)로 정의 된 Id가 있습니까? –

+0

게시물을 업데이트합니다. StoreGeneratedPattern.Identity가 없습니다. – Mediator

답변

3

=>는 데이터베이스에서 새 값이 할당됩니다.

+0

나는 이것을 생각한다. 그러나 ID는 업데이트하지 않습니다. 왜? – Mediator

관련 문제