asp.net mvc - Linq to Sql: Error on InsertOnSubmit -


   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();     } 

when inserting new gallery table, method throws object reference not set instance of object error. gallery not null , neither gallerytable in advance

so problem gallery entity had

   private entityset<tag> _tags;      [system.data.linq.mapping.association(storage = "_tags", otherkey = "tagid")]     public entityset<tag> tags     {         { return this._tags; }         set { this._tags.assign(value); }     } 

and throwing null reference @ this._tags.assign(value); assigned blank entityset _tags variable , problem solved


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -