c# - EF Non-static method requires a target -
i've serious problems following query.
context.characteristicmeasures .firstordefault(cm => cm.charge == null && cm.characteristic != null && cm.characteristic.id == c.id && cm.line != null && cm.line.id == newline.id && cm.shiftindex != null && cm.shiftindex.id == actshiftindex.id && (newareaitem == null || (cm.areaitem != null && cm.areaitem.id == newareaitem.id)));
i targetexception: non-static method requires target
when newareaitem null. if newareaitem not null notsupportedexception: unable create constant value of type 'pqs.model.areaitem'. primitive types or enumeration types supported in context.
things i've checked if they're null: c, newline, actshiftindex 3 variables not null , id accessible.
i dont it... please help.
if u need more information.. dont hesitate ask...
update
i eliminate notsupportedexception
, still got targetexception when newareaitemisnull true.. :/
bool newareaitemisnull = (newareaitem == null); var mc = context.characteristicmeasures .firstordefault(cm => cm.charge == null && cm.characteristic != null && cm.characteristic.id == c.id && cm.line != null && cm.line.id == newline.id && cm.shiftindex != null && cm.shiftindex.id == actshiftindex.id && (newareaitemisnull || (cm.areaitem != null && cm.areaitem.id == newareaitem.id)));
update
i did it. seems query parse can't parse newareaitem(isnull)
because it's not in db model somehow !? have split queries..
bool newareaitemisnull = (newareaitem == null); measurecharacteristic mc; if (newareaitemisnull) mc = context.characteristicmeasures .firstordefault(cm => cm.charge == null && cm.characteristic != null && cm.characteristic.id == c.id && cm.line != null && cm.line.id == newline.id && cm.shiftindex != null && cm.shiftindex.id == actshiftindex.id); else mc = context.characteristicmeasures .firstordefault(cm => cm.charge == null && cm.characteristic != null && cm.characteristic.id == c.id && cm.line != null && cm.line.id == newline.id && cm.shiftindex != null && cm.shiftindex.id == actshiftindex.id && cm.areaitem != null && cm.areaitem.id == newareaitem.id);
does know better solution?
try moving newareaitem == null
outside of query
bool newareaitemisnull = (newareaitem == null);
and replace newareaitem == null
newareaitemisnull
in query.
query parser can operate objects in database, , newareaitem not 1 of them.
Comments
Post a Comment