10

The Linq-To-Sql method is not supported?

 2 years ago
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.
neoserver,ios ssh client

The Linq-To-Sql method is not supported?

advertisements

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

I am trying to perform a SQL "Like" wildcard search using LINQ 2 SQL with the below query public IQueryable<DbHeader> GetHeaders() { return Work.Context.Headers .Include(m => m.Terms.Select(t => t.MetaDataPairs)) .Include(m => m.S

Refactoring the linq-to-sql method that returns corresponding values

I have a simple linq-to-sql statement that matches values in a string[] to the values in a table and returns the matched table values. _table is of type System.Data.Linq.Table<TEntity> public IEnumerable<ZipCode> match(IEnumerable<string>

The linq to sql query can not be translated by error

Here is the query: children = (from r in masterDB.mrrel_Limited2s join s in masterDB.mrconso_SnoMed2014_LimitedToDiseaseBranches on r.AUI2 equals s.AUI join a in masterDB.tbl_patients_problems_problemId_to_SnoMed_Iteration2_before_doc_final_s on s.SC

The Linq to sql query does not return the correct elements

Hi i am having an issue with a query to my db. I have looked through the questions on here and have not found anything similar although my title is similar to some other questions. The site i am working on can create collection requests and then view

The LINQ to SQL field will not be updated (sometimes)

I have a MVC Web Application using the following approach: public class MyController : Controller { public FooRepository fooRepository = new FooRepository(); public BarRepository barRepository = new BarRepository(); public ActionResult UpdateItems(in

LINQ to SQL Designer Does Not Work

After installing VS 2008 SP1, the LINQ to SQL Designer is not generating code. I get an error message: Could not load type ' r' from assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.This often happens if

DataContractSerializer in the LINQ to SQL expression?

I'm new to LINQ expressions and trying to get the following to work: public IQueryable<Models.Powerups.Powerup> GetPowerups(Guid userid) { return from p in dc.Powerups where p.UserId == userid select (Models.Powerups.Powerup) new DataContractSeriali

The specified member type 'Date' is not supported in LINQ to Entities Exception

I got a exception while implementing the following statements. DateTime result; if (!DateTime.TryParse(rule.data, out result)) return jobdescriptions; if (result < new DateTime(1754, 1, 1)) // sql can't handle dates before 1-1-1753 return jobdescript

EF generating & ldquo; The specified method is not supported & rdquo; error in SqlQuery

I am currently using Entity Framework 5 I've tried to code the following: var result = context.Database.SqlQuery<Entity>("SELECT * FROM ref.Entity"); But I get the following error: Specified method is not supported. Can anyone show me a re

The member of specified type is not supported in LINQ to Entities. Only entity initiators, entities, and browsing properties are supported

var result = (from bd in context.tblBasicDetails from pd in context.tblPersonalDetails.Where(x => x.UserId == bd.UserId).DefaultIfEmpty() from opd in context.tblOtherPersonalDetails.Where(x => x.UserId == bd.UserId).DefaultIfEmpty() select new clsPr

Linq to SQL (designer) does not understand the stored procedure

Why can the Linq to SQL designer not understand the following stored procedure and import it correctly? CREATE PROCEDURE dbo.MartinTest @parameter1 INTEGER AS SET NOCOUNT ON SELECT C1, C2, C3 INTO #myTempTable FROM MyTable SELECT C1, C2, C3 FROM MyOt

The specified method is not supported nhibernate 3

i recently migrated from nhibernate 2 to 3, the problem i have is , in most of query i had before i have a problem right now. and i see this error Specified method is not supported although they all work well in hibernate 2 . one on these query is li

The specified member type 'EntityKey' is not supported in LINQ to Entities

I have 2 Entities "UserProfile" and "Agent", they are 1-many relationship. I want to do a query to get a list of Agents by giving the userProfileEntityKey. When I run it, I got this "The specified type member 'EntityKey' is not su

The `.create ()` method does not support nested write fields by default.

I have a big problem regarding the serialization of a Many to Many relationship with intermediate model in DRF: If the request method is get everything works perfectly. But as soon as i try to POST or PUT Data to the API I get the following Error: Tr

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK