471,310 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 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 1734
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Marc Gravell | last post: by
4 posts views Thread by BeSharp | last post: by
6 posts views Thread by =?Utf-8?B?TmVkaW0=?= | last post: by
15 posts views Thread by EDBrian | last post: by
1 post views Thread by Lacutas | last post: by
2 posts views Thread by AAAAA | last post: by
2 posts views Thread by Mucahit ikiz | last post: by
5 posts views Thread by =?Utf-8?B?cmF1bGF2aQ==?= | last post: by
reply views Thread by =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post: by
reply views Thread by rosydwin | last post: by

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.