The Linq-To-Sql method is not supported?
source link: https://www.codesd.com/item/the-linq-to-sql-method-is-not-supported.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The Linq-To-Sql method is not supported?
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.
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;
Related Articles
The search for general characters in the LINQ to SQL query does not run
Refactoring the linq-to-sql method that returns corresponding values
The linq to sql query can not be translated by error
The Linq to sql query does not return the correct elements
The LINQ to SQL field will not be updated (sometimes)
LINQ to SQL Designer Does Not Work
DataContractSerializer in the LINQ to SQL expression?
The specified member type 'Date' is not supported in LINQ to Entities Exception
EF generating & ldquo; The specified method is not supported & rdquo; error in SqlQuery
The member of specified type is not supported in LINQ to Entities. Only entity initiators, entities, and browsing properties are supported
Linq to SQL (designer) does not understand the stored procedure
The specified method is not supported nhibernate 3
The specified member type 'EntityKey' is not supported in LINQ to Entities
The `.create ()` method does not support nested write fields by default.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK