c# LINQ to Entities does not recognize the method 'System.String ToString()' method -
c# LINQ to Entities does not recognize the method 'System.String ToString()' method -
i want select multiple column in db , store in array maintain getting error
linq entities not recognize method 'system.string tostring()' method, , method cannot translated store expression.
it should homecoming me "functioncode-activitycode"
public override string[] getrolesforuser(string username) { dev_context oe = new dev_context(); string role = oe.userrefs.where(x => x.username == username).firstordefault().rolename; string[] result = oe.rolepermissionrefs .where(x => x.rolename == role && x.statuscode == "a") .select(x => new { functioncode = x.functioncode, activitycode = x.activitycode }.tostring()) .toarray(); homecoming result; }
even if work, wouldn't give expected result.you calling tostring
on anonymous object. if want concatenate values can try:
string[] result = oe.rolepermissionrefs .where(x => x.rolename == role && x.statuscode == "a") .select(x => new { x.functioncode, x.activitycode }) .asenumerable() .select(x => string.join("-", x.functioncode, x.activitycode)) .toarray();
the reason why tostring
doesn't work explained in error message.it can't translated sql.so need load result memory (e.g using asenumerable
in above code) , project them.
c# linq entity-framework
Comments
Post a Comment