linq

Find from a hashtable using the value

I have a following hash table: private Hashtable Sid2Pid = new Hashtable(); Sid2Pid.Add(1,10); Sid2Pid.Add(2,20); Sid2Pid.Add(3,20); Sid2Pid.Add(4,30); Now how to get the list of keys from the above hashtable that has a value of 20 using LinQ ...

Is a linq query to ConcurrentDictionary Values threadsafe?

Hello, let's say I have the following code: ConcurrentDictionary<long, long> myDict= new ConcurrentDictionary<long, long>(); Normally every access by key is threadsafe, but is also the following linq query threadsafe? I have not found anything in the docs: http://msdn.microsoft.com/en-us/library/dd287226.aspx if myDict.Values.Any(x ...

LINQ Help for boolean function for a list

How could I construct a LINQ expression to remove values from one list that meet the criteria of a function that returns a boolean? string[] message = "days of the week" message.ToList().RemoveAll(c=>checkShortWord(c)); public static bool checkShortWord(string word) { if ((word.Length > 3) && (!...

How can Entity Framework queries be reused (using methods)?

I'm trying to reuse part of a query, because it's complex enough that I want to try to avoid code duplication. It seems that when calling any method inside a query, you end up with: LINQ to Entities does not recognize the method {X} method, and this method cannot be translated into a store expression What I would like to do...

How to get the second repeated item from a collection of objects using LINQ to object

Hi, I've this Collection for example: 1: A 2: B 3: A 4: C 5: A 6: C I want to get the second repeated item from this collection in a LINQ query, the required result is: 3:A, 6:C ...

Error "The primary key column of type 'DateTime' cannot be generated by the server."

I have a composite primary key (Int and DateTime) on one of my tables. When I try to add a new record using LINQ (with the DateTime field set to "AutoGeneratedValue = true", and getdate() as default value on the server), I get the following errors: The primary key column of type 'DateTime' cannot be generated by the server. Any ide...

In linq how dynamically pass table and column name

I want to write an dynamic linq where i send table and column name this query return me the max row number of the table . SELECT ISNULL(MAX(intProductCode) + 1, 1) AS intProductCode FROM tblProductInfo Above is my T-SQL syntax.I want same output from the linq how to If i write this bellow syntax get same out put but here i can not se...

Issue with Updating Changes in LINQ

I'm having an issue with updating the database. The app shows the updated value, but the database does not. No errors returned. My table has a PK. Using DotConnect for Oracle, but the LINQ syntax is the same. namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataCon...

When rebinding Repeater for 2nd time (1st in Page_Load, 2nd in Page_Prerender) duplicate rows appear

I have designed a user control to present a list of questions to the user. This "question list" control just contains a repeater. There are a wide range of types of question and form fields that must be used to answer the question, so they are implemented as a range of "question input" controls which are dynamically loaded into the ItemT...

Using Linq to return each item only once.

Here's what I'm trying to do. Have a use right a sequence of numbers delimited by spaces. After I save those numbers, I want to return a string of all the numbers only once, even if a number has appeared n number of times in the sequence. string[] tempNumbers = textValue.Split(' '); IEnumerable<string> distinctNumbers = tempNumbers.Whe...

The Big O of Distinct() method with a Custom IEqualityComparer

Anyone knows the Big O of the algorithm used in the Distinct() method, with a custom IEqualityComparer? ...

EF EDM and ObjectQuery include / join

Hi I have these 2 entties in my edm: Parnter members: int id, string firstname, string lastname, Partner_Address partneradress Partner_Address members: int id, int partnerid, date validfrom If i use create my query like this: ObjectQuery.include("Partner_Address") i get a Partner entity and could access Partner_Adress properties (eg...

LINQ .OrderBy single letter then by another letter

Hello Im trying to make a special orderby with Linq. It has to order by S then P then NB then V and then NC. Im not sure if its the best way to de this but this is what i have: repeater.DataSource = query.OrderBy(p => p.Title ?).ThenBy(?).ThenBy(?); ...

Is there an equivalent for Enumerable.Empty<T> that returns IQueryable?

It's possible to do the following: IEnumerable<Person> people = Enumerable.Empty<Person>(); Is there an equivalent for IQueryable...? IQueryable<Person> people = Queryable.Empty<Person>(); ...

Entity Framework getting attribute/value pairs.

I'm working with an existing database, utilizing the Entity Framework for dynamic query builder. This is a key factor here. I don't know what types of objects I'll be working with until runtime, as the user is allowed to select which objects/properties they want with the query builder... So I'm using ObjectQuery<EntityObject>. Everythin...

How to get the difference of two list in C# using LINQ

I've two lists like List<String> LISTONE=new List<String>() and List<String> LISTTWO=new List<String>() and which contains LISTONE "A" "B" "C" LISTTWO "A" "D" "E" and the required out put is LISTTEMP "B" "C" "D" "E" is there any way to do this us...

Trim() a list of strings using dynamic query language to produce a trimmed IQueryable<string>

Is this possible, or am I just trying to way overly shorten my code? I thought it might be something like: IQueryable<string> trimmedStrs = untrimmedStrsArr.AsQueryable<string>().All(s => s.Trim()); But that's no good :( ...

Easier way to "is not in" in dynamic linq language?

I have an array of strings and an IQueryable (called MyTypeQbl). I want to iterate through the strings in the array which do not have a corresponding MyType.MyString. I thought this would be: foreach (string str in stringsArr.Where(s => MyTypeQbl.Count(m => m.MyString == s) == 0)) But is this just more complex than it should be? Is...

How to do linq-to-IEnumerable-style joins in F#

I've got a project that I'm trying to convert to F#, with a fair amount of linq-to-IEnumerable style queries in it. I'm curious what the most elegant way of doing a join of multiple lists would be in F#. For instance if I have a bunch of C# code like the following var joinedList = from val1 in list1 j...

How can I set custom property of an Entity type in LINQ to Entities query and still return a IQueryable<T> ?

Hi, I have a EF4 model where I have Product entity that have one-to-many relation with Task entity (ChildTasks). I have to get some Projects from db based on some user criteria. The Project has one custom property (not associated with any column) named EstimatedProgress where I have to store additional information about Project - compute...