473,382 Members | 1,814 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,382 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 1823
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.