473,804 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Spli t(new char[] {','},
StringSplitOpti ons.RemoveEmpty Entries).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 1844
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.co m

"shapper" <md*****@gmail. comwrote in message
news:ec******** *************** ***********@c58 g2000hsc.google groups.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.Spli t(new char[] {','},
StringSplitOpti ons.RemoveEmpty Entries).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
16436
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 write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
4
549
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.). Assume I want to select rows from a database and check whether a specific column contains keywords from a list of keywords. The following works just fine: List<stringsearchTerms = new List<string>() { "Maria", "Pedro" };
6
1512
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 support - you need to be able to filter the data based on one or more columns (I make the filter in runtime). The data also has to be paged (with user selected sort column). First I wanted to use the LinqDataSource for this, but it does not have a...
15
10876
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 very well. We are now adding a lot more functionality to our filters and could really benefit from using the LINQ to SQL. I have experimented with the Dynamic Linq...
1
6992
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 requested changes. The table I am trying to alter is called RawData, this is defined in a DataSet but has no data columns as these aren't known until some data is imported. As part of my import routine it automatically creates the correct columns...
2
1584
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
2531
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 connString = @"Data Source=.;Initial
5
1669
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 == id) return true;
0
2367
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 occuring enough to be a real cause for concern. The errors occur a couple times a week and the website is hit with constant traffic 24x7. Below are the two errors that are encountered. I had read something about MARS causing errors like this but...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.