linq

. The An object with the same key already exists in the ObjectStateManagerObjectStateManager cannot track multiple objects with the same key.

I am trying to simply update the entity object and I get this error.. All the googling on the error I did takes me to complex explanations... can anyone put it simply? I am working of of this simple tutorial http://aspalliance.com/1919_ASPNET_40_and_the_Entity_Framework_4__Part_2_Perform_CRUD_Operations_Using_the_Entity_Framework_4.5 ...

Linq: Dynamic Query Contruction: query moves to client-side

Hi all, I've been following with great interest the converstaion here: http://stackoverflow.com/questions/3769141/construct-query-with-linq-rather-than-sql-strings with regards to constructing expression trees where even the table name is dynamic. Toward that end, I've created a Extension method, addWhere, that looks like: static pub...

Parsing a string C# LINQ expression

I'm trying to do some really dynamic querying here - preferably without invoking the compiler at runtime though. I have a string containing a LINQ expression, e.g. var s = "from a in queryable where a.Type == 1 select a"; How can I get the resulting IQueryable or Expressions from that? I've seen LINQPad and RavenDb both do this so I...

Recursively (?) compose LINQ predicates into a single predicate.

(EDIT: I have asked the wrong question. The real problem I'm having is over at http://stackoverflow.com/questions/3782940/compose-linq-to-sql-predicates-into-a-single-predicate - but this one got some good answers so I've left it up!) Given the following search text: "keyword1 keyword2 keyword3 ... keywordN" I want to end up with t...

Compose LINQ-to-SQL predicates into a single predicate.

(An earlier question, http://stackoverflow.com/questions/3782799/recursively-compose-linq-predicates-into-a-single-predicate, is similar to this but I actually asked the wrong question... the solution there satisfied the question as posed, but isn't actually what I need. They are different, though. Honest.) Given the following search te...

Strange cast error with Linq and Oracle

I am getting a cast error with Linq to a DataTable that was populated with Oracle. bool isTrue = DataTable.AsEnumerable().Any (x => x.Field<int>("MYNUMBERFIELD") == MYNUMBER); In SQL this works fine as expected. In Oracle is fails with a cast error on the cast. In C# code the same thing happens when you do the following: i...

With LINQ how do you return a string const in the result from the select operator.

In LinqPad I have the following query statements... var genre = "Anime & Animation"; var minRating = 3.0; var topNum = 30; var query = (from g in Genres from t in g.Titles where g.Name==genre && t.Instant.Available==true && t.AverageRating >= minRating orderby t.AverageRating descending select new {t.Name...

get values from nested Dictionary using LINQ. Values of Dictionary are list of lists.

How to get values from nested Dictionary using LINQ. Keys in the Dictionary are integer. Values of Dictionary are list of lists. Seconday level list is a list of array holding integer value. Thanks in advance. ...

get values from a nested dictionary using lambda values of the dictionary are ArrayList of ArrayList

I need to retrieve values from dictionary which stores a ArrayList which in turn has an ArrayList This second ArrayList has int array stored . Now how can I retrieve those integer values. ` Dictionary<int, ArrayList> obj = new Dictionary<int, ArrayList>(); ArrayList objList1 = new ArrayList(); ArrayList objLi...

List all duplicates in List object including quantity

I have List object filled with instances of a custom struct. list.Add(new Mail("mail1", "test11", "path11")); list.Add(new Mail("mail2", "test12", "path12")); list.Add(new Mail("mail1", "test13", "path13")); list.Add(new Mail("mail1", "test14", "path14")); list.Add(new Mail("mail2", "test15", "pat...

How to use LINQ to generate new type of objects

I have two List<T> of objects with different types (i.e., List<Apple> and List<Tiger>). Now I want to combine properties from the 2 objects to generate a new (anonymous) type of objects. How do I achieve with LINQ? ...

LINQ analogues in Scala

Are there any sane analogues to LINQ (.NET) exists for Scala? ...

CompiledQuery with List.Contains (where...in list) functionality?

I'm attempting to write a CompiledQuery using Linq-to-Entities that will replace a stored procedure that takes two array (in this case, comma-delimited TEXT) parameters. Essentially, the SQL is be something like this: *Stored Proc definition* @ArrayParm1 TEXT, @ArrayParm2 TEXT -- etc. SELECT [fieldList] FROM someTable WHERE som...

Injecting a variable into the Mono.CSharp.Evaluator (runtime compiling a LINQ query from string)

I'm using the Mono.CSharp library to emit code. Following another question on SO (http://stackoverflow.com/questions/3407318/mono-compiler-as-a-service-mcs) I managed to get Mono.CSharp evaluating correctly on the Microsoft CLR. To add flexibility in my app I'd like to be able to customize a query at runtime - by allowing the user to p...

SQL query that looks within the same table

Apologies - am not good at SQL. Perhaps this is a simple query - I don't know. What I have is a basic forum table - e.g. id poster title type content postedon parentID in this scheme, if a user asks a question, it is type = 0, and if it is an answer, type = 1. If the entry is an answer, I update the parentID to the id on the question...

Linq: Querying a "Virtual" columns created from one split column

Hi all, I'm working with a pretty nasty looking, but non-changable db. We've got a table, called "Locations" with column, "Position" This column has values like "A SHELF 5" Which means "Case A, Shelf 5". In an ideal world, I'd have a Case and Shelf column, with the values "A" and 5, respectively. What I'm wondering, is if there's a...

Linq to XML to Object

I have an XML in this format which is mapped to corresponding Objects in VB.NET. <Control Name="LoginPage" LabelAlignment="Right" FieldAlignment="Left" DisplayPoweredByLogo="False"> <Fields> <FieldGroup Name="Admin" Visible="True" LayoutPosition="Left"> <AdminID Visible="False" Required="False" EnableChange="False" Max...

Creating methods that DO translate to SQL?

In the database of an application I'm using, there is a record that has a "Date" field. In many places in the code, we need to translate that into a Fiscal Year for grouping, selecting, and filtering. So here are a few examples of what a query might look like: var query = from r in DB.records let fy = r.Date.Month >= 10 ? r....

Returning Dictionary<FileHash, string[]> from Linq Query

Thanks in advance for any assistance. I'm not even sure if this is possible, but I'm trying to get a list of duplicate files using their hashes to identify the list of files associated with the hashes. I have this below: Dictionary<FileHash, string[]> FindDuplicateFiles(string searchFolder) { Directory.GetFiles(searchFolder, "*.*")...

how to query this in linq

Hi i have this SQL SELECT * FROM [dbo].[LeftHand] left outer JOIN [dbo].[Head] ON [LeftHand].[ID] = [Head].[LeftHand_Id] WHERE [Head].[RightHand_Id] Not IN (59,60,63,64,65) or [Head].[RightHand_Id] is null [Head] */ \* / \ 1/ \1 [LeftHand] [RightHand] ([LeftHand may h...