linq

Linq-ToEntities DataSource Assignment Hangs in Winforms

I have a very typical linq-to-entities data binding in WinForms: myGrid.DataSource = myEntities.entity When it reaches that line of code it simply hangs. Similar assignment a different entity work fine elsewhere in the code. The database contains no more than 50 lines of data in all entities (it's a new project) so it's not waiting on...

Using C# , LINQ how to pick items between markers again and again?

Say I have an array of strings: string[] strArray = {"aa", "bb", "xx", "cc", "xx", "dd", "ee", "ff", "xx","xx","gg","xx"}; How do I use LINQ to extract the strings between the "xx" markers as groups? Say by writing them to the console as: cc dd,ee,ff gg ...

drawbacks of linq

What are the drawbacks of linq in general. ...

LINQ: grouping collection

Hello Everyone I am programming space invaders for practise ;-) and works quite well but I have a problem with my invaders returning fire. All invaders are stored in a list and I use linq to group those invaders by their X-location so I can access a group randomly and take the invader that is at the bottom of that column to shoot back....

C# Multiple Linq Query Search Issue

Hello, I have multiple linq queries for searching a database of information based on a single specific piece of criteria per query. e.g. by ID or by Name etc. Currently, the user can search by use of only one query method. The problem is that I want the user to be able to search using multiple criteria, without having to write new quer...

LinqToSQL and auditing changed fields

Here's another one of these LinqToSQL questions where I'm sure I must have missed the boat somewhere, because the behavior of the O/R Designer is very puzzling to me... I have a base class for my LinqToSQL tables, which I called LinqedTable. I've successfully used reflection to get hold of all the properties of the descendant classes a...

Fastest way to get a single record with SubSonic

I am new to SubSonic and Linq Stuff and I am trying a figure out the shortest and optimal way of retrieving a single record. What other way is quicker and requires less code to write than this to get a single record? User user2 = DB.Select().From(User.Schema) .Where(User.PasswordColumn).IsEqualTo(password) .And(User.SINumberColumn).IsE...

SingleOrDefault: How to change the default values?

SingleOrDefault returns null, but what if I want to assign values to represent the object that wasnt found? ...

Is it possible to make LinQ "understand" a classic SQL query??

Hi everyone! Is it possible to make LinQ to SQL read and understand a pure SQL query sucha as "SELECT * from myTable"?? My boss asked me to write directly to database the pure SQL querys in a certain table and this table will have a field named "typeOfSelect", for example. And, in my application, I will have to read this field "typeO...

How can I make a console application that lets me enter LINQ expressions and my program will execute them?

How can I write a console application that prompts me and lets me enter LINQ expressions and it will spit out the results of that LINQ query? What would be the easiest way to parse/evaluate a incoming string as a LINQ expression? ...

Linq to Sql - return selected specified columns

I would like to select only few columns from a certain (Blobs) table. I have fields like: Id, RowVersion, Size, Signature, Blob, and I want to select only first four. I do it like this: (---> is an error place) public List<BlobDetails> GetAllBlobsNames() { RichTekstModelDataContext dc = new RichTekstModelDataContext(); var ...

LINQ Refactoring

Hi guys, I refactored my foreach loop from this before: foreach (KeyValuePair[string, string] param in paramsList) { XmlElement mainNode = xmlDoc.CreateElement("parameter"); mainNode.SetAttribute("name", param.Key); mainNode.SetAttribute("value", param.Value); rootNode.AppendChild(mainNo...

Linq Query with SUM and ORDER BY

I have a (C#) class called Hit with an ItemID (int) and a Score (int) property. I skip the rest of the details to keep it short. Now in my code, I have a huge List on which I need to do the following select (into a new List): I need to get the sum of all Hit.Score's for each individual Hit.ItemID, ordered by Score. So if I have the follo...

List<object>.Contains Expression Tree

I would like to build an Expression that would equate to expected... Expression<Func<ReferencedEntity, bool>> expected = (ReferencedEntity referencedEntity) => foreignKeys.Contains(referencedEntity.Id); Expression<Func<ReferencedEntity, bool>> actual; foreignKeys type is a List<object> Here is what I have so far and I think it would ...

Unit Testing Expression Trees

I recently need to build a Expression tree so I wrote a Test method like so... /// <summary> /// /// </summary> [TestMethod()] [DeploymentItem("WATrust.Shared.Infrastructure.dll")] public void BuildForeignKeysContainsPredicate_shoud_build_contains_predicate() { RemoteEntityRefLoader_Accessor<ReferencedEntity> target = CreateRe...

LINQtoSQL Retreiving a table according to the values of another table where it has a many to many relationship with

I have the following three tables: With LinqToSql I would like to retreive a list of InventoryItems where (pointsName="Level" AND pointsValue <= maxStoreLevel) AND pointsName="Buy Price" and Note that maxStoreLevel is an Integer and it is the value of the points row that has pointsName = "Level". Since you can't use a where inside...

how to process "parallel" sequences in Linq?

Suppose I have 2 enumerations that I know have the same number of elements and each element "corresponds" with the identically placed element in the other enumeration. Is there a way to process these 2 enumerations simultaneously so that I have access to the corresponding elements of each enumeration at the same time? Using a theoretic...

C# - Using LINQ to take two variables into a 2-dimensional array?

I have a list<> of an "region" class with two variables, "startLocation" and "endLocation". I'd like to combine those two into a new sorted 2 dimensional array where its just Location and an integer representing whether its start or an end. For example, if the list has three region objects with [Region 1] : startLocation = 5, endLocati...

How do I create a linq query that gets everything but a specific value

Say I have a linq query select r in db.Roles where r.RoleName DOES NOT contain ("Administrator") select r; It is the does not contain part that has me confused. I realize I can do that .Contains call but how do you do the opposite? Thanks! Update: I found the Exclude method and here is how I used it: var role = (from r in db.Roles...

C# - I know I can do this in LINQ, but I can't get it to work...

I got a list of RegionGroup objects with two properties: an int "number" and a list<> of "Regions". I need to output a distribution of number of Region objects combined for each number. For example, given: [Region 1] - number: 1 - list<> has 5 members [Region 2] - number: 3 - list<> has 2 members [Region 3] - number: 4 - list<> has 9...