c# - MySql & Entity Framework causing "Object reference not set to an instance of an object." -
forgive me if vague...i using mysql connector entity framework based application.
i have record in content table, trying fetch, whenever tries record, i'm getting exception:
object reference not set instance of object.
at line:
data.entities.content content = this.sitedata.content.take(1).singleordefault();
i've checked sitedata instance (...it is), when inspected content
, appeared not have records, i'm assuming take(1)
fails...i wrong.
here stack trace:
[nullreferenceexception: object reference not set instance of object.]
mysql.data.entity.selectstatement.getdefaultcolumnsfortable(tablefragment table) +64
mysql.data.entity.selectstatement.getdefaultcolumnsforfragment(inputfragment input) +90
mysql.data.entity.selectstatement.adddefaultcolumns(scope scope) +87
mysql.data.entity.selectstatement.wrap(scope scope) +37
mysql.data.entity.selectgenerator.wrapifnotcompatible(selectstatement select, dbexpressionkind expressionkind) +69
mysql.data.entity.selectgenerator.visit(dblimitexpression expression) +37 system.data.common.commandtrees.dblimitexpression.accept(dbexpressionvisitor1 visitor) +25
1 visitor) +25
mysql.data.entity.sqlgenerator.visitinputexpression(dbexpression e, string name, typeusage type) +35
mysql.data.entity.selectgenerator.visitinputexpressionensureselect(dbexpression e, string name, typeusage type) +21
mysql.data.entity.selectgenerator.visit(dbprojectexpression expression) +38
system.data.common.commandtrees.dbprojectexpression.accept(dbexpressionvisitor
mysql.data.entity.selectgenerator.generatesql(dbcommandtree tree) +60 mysql.data.mysqlclient.mysqlproviderservices.createdbcommanddefinition(dbprovidermanifest providermanifest, dbcommandtree commandtree) +329
system.data.common.dbproviderservices.createcommanddefinition(dbcommandtree commandtree) +125
system.data.entityclient.entitycommanddefinition..ctor(dbproviderfactory storeproviderfactory, dbcommandtree commandtree) +1411
system.data.entityclient.entityproviderservices.createcommanddefinition(dbproviderfactory storeproviderfactory, dbcommandtree commandtree) +78
system.data.entityclient.entityproviderservices.createdbcommanddefinition(dbprovidermanifest providermanifest, dbcommandtree commandtree) +159
system.data.common.dbproviderservices.createcommanddefinition(dbcommandtree commandtree) +125
system.data.objects.internal.objectqueryexecutionplan.prepare(objectcontext context, dbquerycommandtree tree, type elementtype, mergeoption mergeoption, span span, readonlycollection1 compiledqueryparameters, aliasgenerator aliasgenerator) +453
1 formergeoption) +736
system.data.objects.elinq.elinqquerystate.getexecutionplan(nullable
system.data.objects.objectquery1.getresults(nullable
1 formergeoption) +131
system.data.objects.objectquery1.system.collections.generic.ienumerable<t>.getenumerator() +36 system.linq.enumerable.singleordefault(ienumerable
1 source) +179 system.data.objects.elinq.objectqueryprovider.b__2(ienumerable1 sequence) +41
1 query, expression queryroot) +59
system.data.objects.elinq.objectqueryprovider.executesingle(ienumerable
system.data.objects.elinq.objectqueryprovider.system.linq.iqueryprovider.execute(expression expression) +133
system.data.entity.internal.linq.dbqueryprovider.execute(expression expression) +87 system.linq.queryable.singleordefault(iqueryable`1 source) +251 samscreative.home.page_load(object sender, eventargs e) in g:\software development\projects\samscreative\samscreative\home.aspx.cs:17
system.web.util.callieventhandlerdelegateproxy.callback(object sender, eventargs e) +51 system.web.ui.control.onload(eventargs e) +92
system.web.ui.control.loadrecursive() +54
system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +772
i'm @ loss causing this...any appreciated!
as stated in "comments":
hum...try this:
yourdbcontext xxx = new yourdbcontext(); var query = (from p in xxx select p).firstordefault();
instantiate dbcontext first.
Comments
Post a Comment