sql server - Entity Framework 6 query generates NullReferenceException -


edit: not problem ignorance of basic programming (such trying dereference null object reference).

edit: added stack trace ef within linqpad.

using ef6, have simple query :

var menu = dbcontext.tree.where(t => t.left > 2 && t.right < 10).tolist(); 

this worked right until mysteriously stopped. dbcontext.tree view in sql server 2012. using linqpad5, results expect using built-in connection. setting ef connection project, nre. checking sql, can copy , paste sql query window , proper results. nre without call, also.

i've tried updating model database refresh anything. i've tried removing view model , updating. i've tried deleting model entirely , recreating it. i've restarted visual studio , computer. same nre query. don't know else can try, , nre makes no sense me @ all, given results expect using ef. i'd chalk bug ef if didn't see working previously.

has dealt this? searching online specific set of circumstances has produced nothing.

stack trace :

at system.data.entity.core.entitykey.addhashvalue(int32 hashcode, object keyvalue) @ system.data.entity.core.entitykey.gethashcode() @ system.collections.generic.genericequalitycomparer`1.gethashcode(t obj) @ system.collections.generic.dictionary`2.findentry(tkey key) @ system.collections.generic.dictionary`2.trygetvalue(tkey key, tvalue& value) @ system.data.entity.core.objects.objectstatemanager.trygetentityentry(entitykey key, entityentry& entry) @ system.data.entity.core.objects.objectstatemanager.findentityentry(entitykey key) @ system.data.entity.core.common.internal.materialization.shaper.handleentityappendonly[tentity](func`2 constructentitydelegate, entitykey entitykey, entityset entityset) @ lambda_method(closure , shaper ) @ system.data.entity.core.common.internal.materialization.coordinator`1.readnextelement(shaper shaper) @ system.data.entity.core.common.internal.materialization.shaper`1.simpleenumerator.movenext() @ system.data.entity.internal.lazyenumerator`1.movenext() 

the problem model (tree in example above) has 1 ore more properties not nullable (and possibly marked not nullable in mapping) but corresponding column in data store nullable. exception manifest there record being retrieved had null value 1 of column(s).

  • model fix - when updating model sure use nullable<t> or ? nullable value types , if have mappings defined (either via attributes or in types inherit entitytypeconfiguration) specify property optional there.
  • data store fix - alternatively change data store schema , data align expected in model.

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -