2011-02-24 1 views
0
private Table<Gallery> galleryTable; 
    public GalleryRepository (string connectionString) { 
     dc = new DataContext(connectionString); 
     galleryTable = dc.GetTable<Gallery>(); 
    } 

    public void SaveGallery(Gallery gallery) { 

     if (gallery.GalleryId == 0) 
      galleryTable.InsertOnSubmit(gallery); 
     else if (galleryTable.GetOriginalEntityState(gallery) == null) { 
      galleryTable.Attach(gallery); 
      galleryTable.Context.Refresh(RefreshMode.KeepCurrentValues, gallery); 
     } 
     galleryTable.Context.SubmitChanges(); 
    } 

테이블에 새 갤러리를 삽입 할 때 메서드는 개체 오류의 인스턴스로 설정되지 않은 개체 참조를 throw합니다. 갤러리는 null이 아닌없고, 어느 쪽도InsertOnSubmit에 대한 LINQ : 오류

답변

0

그래서 문제가 내가

private EntitySet<Tag> _Tags; 

    [System.Data.Linq.Mapping.Association(Storage = "_Tags", OtherKey = "TagId")] 
    public EntitySet<Tag> Tags 
    { 
     get { return this._Tags; } 
     set { this._Tags.Assign(value); } 
    } 

했다 내 갤러리 엔티티와 있었다 사전에 galleryTable 감사하고 그래서 내가 할당이 this._Tags.Assign(value); 에 null 참조를 던지고 _Tags 변수에 대한 빈 EntitySet 및 문제 해결