473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Linq. Why do I get this error?

Hello,

I am using the following Linq Query:

var filter = (from t in database.Tags
where t.Name.StartsWith(q,
StringComparison.CurrentCultureIgnoreCase)
orderby t.Name
select t);

But I am getting an error:

Server Error in '/' Application
The method 'StartsWith' has a translation to SQL, but the overload
'Boolean StartsWith (System.String, System.StringComparison)' does
not.

Description:

An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details:

System.NotSupportedException: The method 'StartsWith' has a
translation to SQL, but the overload 'Boolean
StartsWith(System.String, System.StringComparison)' does not.

Does anyone has any idea what am I doing wrong?

Thanks,
Miguel
Jul 16 '08 #1
2 4348
On Jul 16, 3:04*pm, shapper <mdmo...@gmail.comwrote:
Hello,

I am using the following Linq Query:

* * * var filter = (from t in database.Tags
* * * * * * * * * * * where t.Name.StartsWith(q,
StringComparison.CurrentCultureIgnoreCase)
* * * * * * * * * * * orderby t.Name
* * * * * * * * * * * select t);

But I am getting an error:
<snip>
System.NotSupportedException: The method 'StartsWith' has a
translation to SQL, but the overload 'Boolean
StartsWith(System.String, System.StringComparison)' does not.

Does anyone has any idea what am I doing wrong?
Yes - you're using a method call which doesn't have a direct
translation into SQL. In other words, LINQ to SQL is happy to
translate some overloads of StartsWith, but not the one you're using.

It's possible that in *this particular case* using ToLower and
StartsWith separately is the right way to go - but look at the
generated SQL and see whether it's what you think it should be, taking
culture into account.

Jon
Jul 16 '08 #2
On Jul 16, 6:34*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jul 16, 3:04*pm, shapper <mdmo...@gmail.comwrote:
Hello,
I am using the following Linq Query:
* * * var filter = (from t in database.Tags
* * * * * * * * * * * where t.Name.StartsWith(q,
StringComparison.CurrentCultureIgnoreCase)
* * * * * * * * * * * orderby t.Name
* * * * * * * * * * * select t);
But I am getting an error:

<snip>
System.NotSupportedException: The method 'StartsWith' has a
translation to SQL, but the overload 'Boolean
StartsWith(System.String, System.StringComparison)' does not.
Does anyone has any idea what am I doing wrong?

Yes - you're using a method call which doesn't have a direct
translation into SQL. In other words, LINQ to SQL is happy to
translate some overloads of StartsWith, but not the one you're using.
For completeness, here's the list of unsupported methods:

http://msdn.microsoft.com/en-us/library/bb386970.aspx

In particular:

"Unsupported String methods in general:
Culture-aware overloads (methods that take a CultureInfo /
StringComparison / IFormatProvider)."
Jul 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
1
by: =?Utf-8?B?UGVkcm8=?= | last post by:
Hi I have VS .NET 2005 and I install LinQ preview for C#. I'm try to make some thing using LINQ. IT returns error in this sentence : var query = from p in people.People from s in...
7
by: Andy B | last post by:
Just wondering why linq is more useful than datasets? The stuff I do doesn't seem to be too complicated to use linq with it. If I did use linq with it now, I would be doing almost the exact same...
24
by: luowan | last post by:
Hi I am currently building an application on .NetCF 3.5 in C#. The application needs to process xml files. I am thinking about using LINQ to process XML. I wrote a piece of code to modify the...
9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
1
by: ph_haenggi | last post by:
Hi folks I am pretty new to linq and in one of my first samples I tried to do the following: In my sample-database I have a table which has some columns and one of them has the type 'xml'. ...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
4
by: Andrus | last post by:
Checking Client-only framework subset in VS2008 SP1 project properties causes in my application compile error The type 'System.Data.Linq.ITable' is defined in an assembly that is not...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.