Reputation: 6353
I'm using a query that tries to find a matching unique identifier (guid) such as
var myUsers = from u in table
where u.UniqueIdentifierId == MyClass.GetCurrentUserId()
select u;
This throws the Method Not Supported error for my custom function. I recoded it to do this
string guid = MyClass.GetCurrentUserId().ToString();
where u.UniqueIdentifierId.ToString() == guid
And this works. I want to know if there are any other work arounds that do not require creating a temporary variable. Thanks.
Upvotes: 0
Views: 425
Reputation: 58522
Did you try?
var myUsers = from u in table
where u.UniqueIdentifierId == MyClass.GetCurrentUserId().ToString()
select u;
This would force LINQ to SQL to use string comparison(which is why the second one worked)
Upvotes: 1
Reputation: 172646
You can't call it in the query, because LINQ to SQL can't translate this. It tries to transform this in a SQL call. What you must do is call this method outside of the LINQ query, as follows:
var guid = MyClass.GetCurrentUserId();
var myUsers =
from u in table
where u.UniqueIdentifierId == guid
select u;
Upvotes: 3