2010-11-29 3 views
1

"개체 관계형 디자이너"를 사용하여 SQL 데이터베이스 테이블의 엔터티를 만듭니다.왜 LINQ To SQL 프록시 클래스는 INotifyPropertyChanging 및 INotifyPropertyChanged를 구현합니까?

질문 : 일부 클래스는 INotifyPropertyChanging, INotifyPropertyChanged 등을 구현하는 이유는 무엇입니까?

INotifyPropertyChanging, INotifyPropertyChanged을 구현하지 않는 LINQ To SQL 엔터티를 사용하여 데이터베이스의 일부 데이터를 업데이트하려고 할 때 문제가 발생했습니다.

엔티티 defeniion :

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.user_to_user")] 
public partial class user_to_user 
{  
    private int _user_id1; 

    private int _user_id2; 

    private string _relation_type; 

    public user_to_user() 
    { 
    } 

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_user_id1", DbType="Int NOT NULL")] 
    public int user_id1 
    { 
     get 
     { 
      return this._user_id1; 
     } 
     set 
     { 
      if ((this._user_id1 != value)) 
      { 
       this._user_id1 = value; 
      } 
     } 
    } 

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_user_id2", DbType="Int NOT NULL")] 
    public int user_id2 
    { 
     get 
     { 
      return this._user_id2; 
     } 
     set 
     { 
      if ((this._user_id2 != value)) 
      { 
       this._user_id2 = value; 
      } 
     } 
    } 

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_relation_type", DbType="VarChar(50) NOT NULL", CanBeNull=false)] 
    public string relation_type 
    { 
     get 
     { 
      return this._relation_type; 
     } 
     set 
     { 
      if ((this._relation_type != value)) 
      { 
       this._relation_type = value; 
      } 
     } 
    } 
} 

의 DataContext :

private Table<user_to_user> friendsTable = new BSocialDBDataContext().GetTable<user_to_user>(); 

가 나는 시도 :

public void FriendshipOffer(int visitor_id, int owner_id) 
    { 
     var relation = friendsTable.FirstOrDefault(u => (u.user_id2 == visitor_id && u.user_id1 == owner_id)); 
     relation.relation_type = "friend"; 

     friendsTable.Context.SubmitChanges(); 
    } 

답변

1

이 LINQ 문 반환 된 데이터에 포함 된 개체의 키인가?

+0

user_to_user는 coccection의 테이블이며 기본 키가 없어야합니다. user_to_user 테이블에 기본 키를 포함하지 않고 LINQ to SQL을 사용하여 udate를 만들 수 있습니까? – Turach