c# - Comparing GUID to string in LINQ to Entites throws error -
this question has answer here:
edit, not duplicate. suggested links want me call tostring()
running .count()
, trying greater comparison calling tostring()
not correct answer.
i trying fill variable using if
shortcut when run error
linq entities not recognize method 'system.guid parse(system.string)' method, , method cannot translated store expression.
the code running is
isadmin = (db.yaf_prov_rolemembership .where(rm => rm.userid == userkey && rm.roleid == guid.parse("adsfasd654asdf816asdf")) .count() > 0) ? true : false;
if take away guid.parse
, straight comparison error
operator == cannot applied operands of type system.guid , string
what needs done in order compare guid string in linq query?
don't know why dave deleted answer - should move string parsing out of store expression. otherwise entity framework tries convert guid.parse
method call sql, , fails that:
var adminroleid = guid.parse("adsfasd654asdf816asdf");
also use queryable.any
simplify query:
isadmin = db.yaf_prov_rolemembership .any(rm => rm.userid == userkey && rm.roleid == adminroleid);
Comments
Post a Comment