c# - Extension method can't be used in LINQ Expression Tree -
i have tried use extension method in linq query following way (ef code first):
user in db.users join data in db.data on user.id equals data.user_id data.available.tobool()
the db.users
, db.data
variables dbset types.
then got following error:
an exception of type 'system.notsupportedexception' occurred in userdata.dll not handled in user code
additional information: linq entities not recognize method 'boolean tobool(system.string)' method, , method cannot translated store expression.
the extension method simple:
public static bool tobool(this string source) { return source=="aa"; }
so looked expression trees , created expression:
pivate readonly system.linq.expressions.expression<func<data, bool>> proper = d => d.name.tobool();
now use this:
user in db.users join data in db.data.where(proper) on user.id equals data.user_id
i still have same error.
what else should use?
you can use extension methods this:
public static iqueryable<user> hasdata(this iqueryable<user> u) { return u.datas.any(); }
used like:
var u=db.users.hasdata();
but return users have data, assuming have navigation property on users data called datas
(and yes, know plural of datum data)
Comments
Post a Comment