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();
}
将新图库插入表中时,该方法会引发 Object reference not set to an instance of an object 错误。画廊不是空的,galleryTable 也不是提前谢谢