473,396 Members | 2,029 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,396 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 4353
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.