473,216 Members | 1,285 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,216 software developers and data experts.

Linq Query. Please, help. Going crazy ...

Hi,

On a form I have an input where tags are inserted in a CSV format.

Then on my code I convert the CSV string to a List<Tag>. Tag is an
object with two properties: TagID and Name
So when I do the conversion I only fill the Tags names ...

Then I use a join to find these tags into my database.Tags and get
their ID's.

This is what I have:

// Parse form post tags
List<Tagform = paper.Tags.Split(new char[] {','},
StringSplitOptions.RemoveEmptyEntries).Select(t =new Tag { Name =
t.Trim() }).ToList();

// Define updated post tags
List<Tagupdated = new List<Tag>(from t in database.Tags
join f in form on t.Name
equals f.Name
select t).ToList();

I debugged and the "form" list has the names of the tags I inserted.
And those names do exist in database.Tags.

However, I always get the following error on my second query:
Local sequence cannot be used in LINQ to SQL implementation of query
operators except the Contains() operator.

I have no idea why do I get this. My code seems ok ... I tried
everything I could think of to solve this.

Does anyone knows why do I get this?

Thanks,
Miguel
Aug 27 '08 #1
1 1816
Well, the error is pretty self-explainitory. You are querying a
database, and then trying to see if the ids are in the database. LINQ to
SQL doesn't know how to take the local sequence (your list of tags) and turn
that into a list to compare against in the database when it sends the query
over.

In this instance, you might be better off passing your comma-delimited
list to a stored procedure which will parse the list and then return your
result set (looking for matching tags). With SQL Server 2005, you can parse
the list easily with a CLR table-valued function which will return a set of
the tags, and you can join (or check with EXISTS) to see if the tag exists.

Another option would be to generate the lambda expression yourself,
using an OR statement (you can't compose with WHERE since that will produce
an AND expression).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"shapper" <md*****@gmail.comwrote in message
news:ec**********************************@c58g2000 hsc.googlegroups.com...
Hi,

On a form I have an input where tags are inserted in a CSV format.

Then on my code I convert the CSV string to a List<Tag>. Tag is an
object with two properties: TagID and Name
So when I do the conversion I only fill the Tags names ...

Then I use a join to find these tags into my database.Tags and get
their ID's.

This is what I have:

// Parse form post tags
List<Tagform = paper.Tags.Split(new char[] {','},
StringSplitOptions.RemoveEmptyEntries).Select(t =new Tag { Name =
t.Trim() }).ToList();

// Define updated post tags
List<Tagupdated = new List<Tag>(from t in database.Tags
join f in form on t.Name
equals f.Name
select t).ToList();

I debugged and the "form" list has the names of the tags I inserted.
And those names do exist in database.Tags.

However, I always get the following error on my second query:
Local sequence cannot be used in LINQ to SQL implementation of query
operators except the Contains() operator.

I have no idea why do I get this. My code seems ok ... I tried
everything I could think of to solve this.

Does anyone knows why do I get this?

Thanks,
Miguel

Aug 27 '08 #2

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...
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
6
by: =?Utf-8?B?TmVkaW0=?= | last post by:
I am starting a new web application and I was planning on using linq but i have a bunch of problems. most forms will display some data from the database, but there always has to be a filtering...
15
by: EDBrian | last post by:
My problem is this. Our clients create different fields they want to collect and we allow them build dynamic filters, reports etc... We run some TSQL to actually create the column and all works...
1
by: Lacutas | last post by:
Hi I'm having some problems getting a dynamic LINQ query to work on my DataSet. The idea is that a user selects certain criteria, and then the LINQ query filters through the dataset making the...
2
by: AAAAA | last post by:
Hi guys I have a one question, is Linq to Sql good in pefornace? is better that traditional method? ismore than speed?? or is same? Thanks.. Regards Cesar
2
by: Mucahit ikiz | last post by:
I cant make a full dynamic query in LINQ I have 2 situation methods (only_exp_query, only_tbl_query) those are working. .... using System.Linq.Dynamic; using System.Data.Linq; .... string...
5
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
linq on objects... want to find if the object exist in its collection if I have a loop searching in the collection foreach (myClass r in collections) { if (r.field01 == type && r.field02...
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.