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
Post a Comment