linq

Modifying values directly using LINQ?

Is it possible to modify elements of a collection, say List, LinkedList, etc using something like: collection.Do ( action ) which does something like: item.Value = 0 (for each item) I know enumerators only give the value, not the reference, hence the question. How would one do this using LINQ? ...

How do I dynamically create an Expression<Func<MyClass, bool>> predicate?

Hi all, How would I go about using an Expression Tree to dynamically create a predicate that looks something like... (p.Length== 5) && (p.SomeOtherProperty == "hello") So that I can stick the predicate into a lambda expression like so... q.Where(myDynamicExpression)... I just need to be pointed in the right direction. Thanks. Ed...

LINQ to XML - How does it work?

My question is essentially a simple one, though I'm looking for as in-depth an answer possible here: how does LINQ to XML work behind the scenes? Now, I have had a fair amount of experience working with LINQ to XML for various applications, so it's interfaces is nothing strange to me, but I am quite clueless as to how the internals oper...

Need some help ordering a Linq result.

Hi folks, I have some Linq code, that works fine. It retrieves a list of board posts ordered by the most recent. The catch here is the order by ... it orders by the most recent COMMENTS. So if a board post just got a comment, then it will be up the top of the list (ie. most recent). kewl ... but what about new board posts that just g...

ADO Entity SubmitChanges not submiting

I am using a Domain Service Class linked to a Linq-to-Sql Context. Using breakpoints it successfully Adds, context.Company.Add(NewCompany); Am calling this from Silverlight,but the saving part seems to fail... context.SubmitChanges(); As in, I get no errors, nor does it add to the database. All my tables have a relation to each oth...

Conditional Linq Queries in VB.NET

I'm triying to do exactly the same thing described here, but in VB.NET I tried all of the C# to VB converters but no one seems to work with LINQ. I'm totaly new to C#, so any help will be appreciated ! public static IQueryable<Type> HasID(this IQueryable<Type> query, long? id) { return id.HasValue ? query.Where(o => i.ID.Equals(id....

Group By Multiple Columns - LINQ

How can I do GroupBy Multiple Columns in LINQ Something as in SQL : SELECT * FROM <TableName> GROUP BY <Column1>,<Column2> How Can i convert below to LINQ QuantityBreakdown ( MaterialID int, ProductID int, Quantity float ) INSERT INTO @QuantityBreakdown (MaterialID, ProductID, Quantity) SELECT MaterialID, ProductID, ...

LINQ - dynamic WHERE clause?

What is the best way to assemble a dynamic WHERE clause to a LINQ statement? I have several dozen checkboxes on a form and am passing them back as: Dictionary<string, List<string>> (Dictionary<fieldName,List<values>>) to my LINQ query. public IOrderedQueryable<ProductDetail> GetProductList(string productGroupName, string productTypeNa...

Left join using LINQ

Could someone give me an example of how to perform a left join operation using LINQ/lambda expressions? ...

How do I select tokens from a string using LINQ?

I want to select a token out of a string if it exists in the string, I've got as far the following but I'm unsure why it doesn't compile: IList<string> tokens = _animals.Split(';'); Func<string, bool> f1 = str => str.Contains("Dog"); Func<string, Func<string, bool>, string> f2 = str => Equals(f1, true); var selected = tokens.Select(f2...

LINQ to SQL, Stored Procedures and the Methods Pane (more like Methods PAIN!)

I'm new to LINQ and am having a small issue. I created a DBML file and dragged all of my tables to the design surface. Now, when I try to drag a stored procedure to the methods pane, Visual Studio thinks a second and then doesn't do anything. My method does not show up in the methods pane. Is some error occurring behind the scenes? If s...

LINQ vs. DataTable.Select - How can I get the same results?

Hi, I'm trying to rewrite a direct (disconnected) DataSet.DataTable.Select to LINQ for a textual search: string search = "ProductNo like '%" + searchpattern + "%' OR ProductName like '%" + searchpattern + "%' OR Description like '%" + searchpattern + "%'"; DataSetProducts.sk_productsRow[] dsp = (DataSetProducts.sk_productsRo...

Creating Models in ASP.NET MVC

I'm just starting a project in ASP.Net MVC with LINQ to Entities and I was wondering if there was a nice, clean way of defining models that creates the appropriate tables in the database for me. I'm most familiar with Django (in terms of MVC frameworks) and am looking for the .Net equivalent of models.py so I can have everything versione...

calling a SP which returns a long select return using LINQ

I am calling a SP using linq and the SP returns a very long string. but when i receive the string its truncated. is there any way to increase the return length in linq? ...

C# Generic List Union Question

I'm trying to merge 2 lists using "Union" so I get rid of duplicates. Following is the sample code: public class SomeDetail { public string SomeValue1 { get; set; } public string SomeValue2 { get; set; } public string SomeDate { get; set; } } public class SomeDetailComparer : IEqualityComparer<SomeDetail> { bool IEqual...

Tracing LINQ TO SQL generated queries in ASP.NET MVC

Hello, Quick question on LINQ to SQL generated queries output. I am in a ASP.NET MVC project, Visual Studio 2008, and I am trying what's suggested in MSDN documentation: MyDataContext _dc = new MyDataContext(); _dc.Log = Console.Out; But nothing is being shown on "Output" window (CTRL+Alt+O). Is there is something else I need to co...

LINQ - Joins in a dynamic query

Because of some business decisions I need to change a bit of what I was doing. Yay me. :) Currently, I have: public IOrderedQueryable<ProductDetail> GetProductList(string productGroupName, string productTypeName, Dictionary<string,List<string>> filterDictionary) { string whereClause = "ProductGroupName='" + productGroupName + "' ...

Compare two IQueryable instances

I have two IQueryable instances - objIQuerableA and objIQueryableB and I want to obtain only elements that are present in objIQuerableA and not in objIQuerableB. One way is to use a foreach loop but I wonder if there is a better method. ...

IQueryable<T> with ASP.NET MVC - Can you use this if Model currently not using LINQ?

If you have a Model whose classes are not using LINQ, can you still somehow take advantage and use the IQueryable for use with paging in MVC? ...

Conversion SQL to LINQ

How can the below be converted to LINQ SELECT Q.MaterialID AS MaterialID, Q.ProductID AS ProductID, QB.Quantity AS Quantity, Q.ParameterID AS ParameterID, SUM((Q.ParameterValue * Q.Quantity)/Q.TotalTonnes) AS ParameterValue FROM @Quality Q INNER JOIN @QuantityBreakdown QB ON ((Q.MaterialID = QB.MaterialID) OR (Q.MaterialID IS NUL...