linq

Dynamic 'table' name in LINQ to entities

I need to select from varying levels of reporting department tables, i.e. Dept1, Dept2, Dept3, ect. [1] depending on which reporting level the user chooses. How can I dynamically express the 'table' to select from based on a given string parameter, which is the table name? [1] Easy points (lets talk) for anyone that can help me out of ...

Linq query to retrieve: Customers, Orders and OrderLineItems

I have a table containing a list of customers, a second table containing orders placed by my customers and a third table containing the line items for the orders. I would like to be able to use a Linq query to get the customer name, the number of orders and the total value of all the orders placed by this customer. Assuming the follow...

Method syntax join onto ObjectQuery in LINQ to Entities

For my client's sake, I have forgone pride and dignity and opted for the exampled means of choosing an entityset to select from, but I need to join this to another, fixed, entityset, and this challenge is beyond me today. I need to project a set of attributes from both Department*n,* and another entity set called Sites. I can join Depar...

LINQ-to-List and IEnumerable issues

I am querying an HTML file with LINQ-to-XML. It looks something like this: <html> <body> <div class="Players"> <div class="role">Goalies</div> <div class="name">John Smith</div> <div class="name">Shawn Xie</div> <div class="role">Right Wings</div> <div class="name">Jack Davis</div> ...

Chaining databound LINQ queries in LINQ to DataSet

I am trying to perform a query on a query result, but I am getting an error: “The method or operation is not implemented”. Can I chain queries in this way? For example, I have a Northwind typed DataSet. I do: queryResult = From product In NorthWindDataSet.Products Where (product.UnitsOnOrder > CInt(txtUnitsOnOrde...

Non-linear scaling of .NET operations on multi-core machine

I've encountered a strange behavior in a .NET application that performs some highly parallel processing on a set of in-memory data. When run on a multi-core processor (IntelCore2 Quad Q6600 2.4GHz) it exhibits non-linear scaling as multiple threads are kicked off to process the data. When run as a non-multithreaded loop on a single cor...

C# Split a string into equal chunks each of size 4

E.g. Input string str = "1111222233334444"; return value ArrayList A where A[0] = "1111", A[1] = "2222", etc. Use of Linq or reg ex would be good. ...

[Linq to SQL] Multiple foreign keys to the same table

I have a reference table with all sorts of controlled value lookup data for gender, address type, contact type, etc. Many tables have multiple foreign keys to this reference table I also have many-to-many association tables that have two foreign keys to the same table. Unfortunately, when these tables are pulled into a Linq model and th...

How do I order an array of floating point numbers using a criteria other than size, using LINQ?

For example, I have an array of floating point numbers: float[] numbers = new float[] { 1, 34, 65, 23, 56, 8, 5, 3, 234 }; If I use: Array.Sort(numbers); Then the array is sorted by the size of the number. I want to sort the numbers by another criteria, so element A should go before element B if f(A) < f(B), rather than the usual ...

What's the appropriate type for a lazyloaded property?

If I have a Customer class and want to add a Orders property which would return all orders for this customer, what would be the appropriate type for the Orders property? Some of the possible choices I can think of: List IList IEnumerable ...

How do I invoke an extension method using reflection?

I appreciate that similar questions have been asked before, but I am struggling to invoke the Linq Where method in the following code. I am looking to use reflection to dynamically call this method and also dynamically build the delegate (or lambda) used in the Where clause. This is a short code sample that, once working, will help to fo...

Linq to Objects: does GroupBy preserve order of elements?

Does Enumerable.GroupBy from LINQ to Objects preserve order of elements in the groups? ...

How can I speed up my pagination code in ASP.NET MVC with Azure?

I'm using ASP.NET MVC and Azure Table Storage in the local development fabric. My pagination code is very slow when working with a large resultset: var PageSize = 25; var qResult2 = from c in svc.CreateQuery<SampleEntity>(sampleTableName) where c.PartitionKey == "samplestring" selec...

LINQ table join with entity Framework

Hi there, In my datbase I have TableA, TableB and TableC TableB has just 2 columns, the primary key of TableA and TableC, so it really defines a one to many relationship between the two tables What i want to do using SQL is: SELECT * FROM TablesA a JOIN TablesB b ON a.AID = b.AID WHERE b.BID = 1 In the Entity Framwork is doesn't c...

entity-framework, how to project into a list

I've been using linq2sql on a few projects, but i decided it was time to try out EF as its supposed to be more powerful and better. There are a few things that is really annoying tho. One of them is projecting a result into a list, this works well in l2sql but not in EF. public class bo.Transaction { public long Id { get; set; } pub...

how to add(or ignore) XML namespace when using XElement.Load

I am creating XML using Linq to XML and C#. It all works great except when I need to manually add in a row in the XML. This row is only added if I have a value to pass through to it, otherwise I just ignore the entire tag. I use XElement.Load to load in the string of text that I store in a string but when I attach it to the XML it alway...

LinqToSql update problem when switching parents

I am trying to perform a straighforward update using LinqToSQL, and just cannot get it to work. Here's the data model: there is a timesheet_entry and customer. One customer has many timesheet_entries. It's a simple foreign key relationship. If I'm editing an existing timesheet_entry, I get an exception if I change the customer_id. Her...

Is the Specification Pattern obsolete when you can use Dynamic LINQ?

Wikipedia states that the Specification Pattern is where business logic can be recombined by chaining the business logic together using boolean logic. With respect to selecting filtering objects from lists or collections it seems to me that Dynamic LINQ allows me to accomplish the same thing. Am I missing something? Are there other be...

NHibernate Linq Like Query Question

Is there any way to make NHibernate.Linq generate a like query on an integer field? The SQL that I want it to generate is: select IntegerColumn from Table where IntegerColumn like '%StringValue%' I've tried something like: from entity in _session.Linq<Entity> where entity.IntegerColumn.ToString().Contains(StringValue) select enti...

Print Data to screen based off of a query in ASP.NET MVC?

I have an application I'm working on where I want to loop through some data where a flag in the data is set to 1 or 2 and print it to screen. The idea I'm working on using is from one of the MVC tutorials: <ul> <% For Each m As Movie In ViewData.Model%> <li><%= m.Title %></li> <% Next%> </ul> But I want to do similar to the abo...