c# - Unable to create a constant value of type . Only primitive types or enumeration types are supported in this context -
c# - Unable to create a constant value of type . Only primitive types or enumeration types are supported in this context -
i have next method generic check exist,
public virtual bool checkexist(t entity) { var context = new etrdataentities(); iqueryable<t> dbquery = context.set<t>(); if (dbquery.any(e => e == entity)) { homecoming true; } homecoming false; }
however returns exception:
unable create constant value of type . primitive types or enumeration types supported in context.
please advice,
many thanks,
try changing code taking in type t next method name, this:
public virtual bool checkexist<t>(t entity) { var context = new etriksdataentities(); iqueryable<t> dbquery = context.set<t>(); if (dbquery.any(e => e == entity)) { homecoming true; } homecoming false; }
you may want restrict type classes only, this:
public virtual bool checkexist<t>(t entity) t : class { var context = new etriksdataentities(); iqueryable<t> dbquery = context.set<t>(); if (dbquery.any(e => e == entity)) { homecoming true; } homecoming false; }
c# entity-framework
Comments
Post a Comment