linq

Get all objects from a tree with a particular property using Linq

I have a class structure which looks like: class TestResults { public bool IsSuccess; public bool IsFailure; public IList<TestResults> SubTestResults; } So, a test has multiple subtests, and the above captures the results. I want to find all of the TestResults which have IsFailure = true. Starting with: var failures = fro...

How Would I Write This In LINQ2SQL?

I am slowly porting over an app from MySQL to use Linq2Sql - but one query has stumped me a bit. SELECT * FROM Pages WHERE DomainID = @reportid AND (PageContent REGEXP 'display\:[ \t]*none') > 0 ORDER BY URL ASC Any ideas on how I would write something like this with Linq2SQL? Its the REGEXP bit thats got me stumped? ...

How to convert Linq query to a DataTable, DataSet or DataView?

Is there an easy way to do this or do I just need to go through each record and insert it into whatever data structure I go with? I need it in this format in order to pass it to a third party software called Aspose. ...

Why can't I pass an anonymous type as a parameter to a function?

I was trying to do something like below but it doesn't work. Why won't .NET let me do this? private void MyFunction(var items) { //whatever } ...

Update asp.net listview with LINQ, programmatically

I'm trying to find a good code sample to update a database entry in my listview control. I suppose I would need to extract the ID from somewhere (some label control?). I am using LINQtoSQL to talk with the database. protected void lvTargets_ItemUpdating(object sender, ListViewUpdateEventArgs e) { InventoryDataContext...

Linq Join Problem

Hi, i want to use linq to fetch data from datatable.I have 2 tables in Cache and i want to join these tables then get value from resultset.I pasted Original Sql query and my linq query here.My linq query returns nothing.Where do i miss?My original sql query returns 1 row ,but q1 is nothing 'Original Sql query select b.FL_DSD f...

Creating an XElement item in a Linq expression

I’m using Linq to create a list of objects. Shown below is the expression I am using. The problem I have is that at runtime it isn’t happy with the “RawXMLDocument = XElement.Parse(t.Message)” line. The “RawXMLDocument” property takes an XElement. Is there a way to convert the string version of the XML (held in Message) into an XElement ...

Why will linq to sql not allow a meber with an "override" inheritance modifier in the where clause?

Hi, I'm getting a InvalidOperationException when trying to run this code: database.Produkts.SingleOrDefault<Produkt>(x => x.Kod == "123") It only occurs when the Kod property has an override modifier. I need it this way because the entity class is derived from another class that resides in a separate assembly. Here's how the classes...

Dynamic Data query.Provider.Execute(query.Expression) analog for EF4

I'm porting a Dynamic Data project from L2S with DD preview 4 to EF with .NET 4. My custom code which works with MetaTable.GetQuery() results has stopped working. I have used the following code to apply ordering/filtering expressions to the MetaTable contents: public static IEnumerable GetOrderedItems(this MetaTable table) { var que...

User's generated specifications

I want to let my users create specifications to be executed in a nhibernate.Linq query. Is it possible? I ask the user to write a query string (HQL I suppose) so it will be serializable and in a combobox the user can apply it to current results ...

Query File System Info Dynamically using LINQ

Hi I need to be able to return a list of files that meet some dynamic criteria. I've tried to do this using LINQ. I've found that it is possible to use dynamic LINQ using the System.Linq.Dynamic namespace that it is mentioned in Scott Gu's Blog. But I'm not sure if can be used for what I need it for. So far I get all the files but ...

C# MVC: Func<Table1, "runtime type"> How do I get a dynamic type?

Hey, I'm trying to sort a custom data grid of columns based on what the user clicked. The variable "sort" is being passed to the controller but is just a string saying what column is to be sorted. I need to get the Type of that column to be used in a LambdaExpression... heres the code ParameterExpression param = Expression.Parameter(ty...

Dynamic Expression API (Dynamic.cs) Not properly parsing expression in .net 3.5

Hi I'm having trouble getting this API working in .net 3.5 (works fine in 4.0). Basically I have following code List<ParameterExpression> parameters = new List<ParameterExpression>(); parameters.Add(Expression.Parameter(typeof(double), "R0C6")); parameters.Add(Expression.Parameter(typeof(double), "R0C7")); parameters.Add(Expres...

Linq IEnumerable Select Question - Can I do all of this inside my select?

Hi All, I had a quick question. Can I do all of this logic inside the select statement? var entries = atisDAO.GetPME(xl, null); response.Data.Detectors = new List<DetectorDetails>(entries.Select(pme => new DetectorDetails {ID = pme.PlaceNum.ToString()})); if(response.Data.Detectors.Any()) { response.Data.Detectors.ForEach(d =>{ ...

How to cast a GroupedEnumerable?

I am playing about with the IQueryProvider.Execute command and am passing in an expression which is part of my expression tree project. This command gives me back an object which can be either an OrderedEnumerable or a GroupedEnumerable depending on the original expression. A GroupBy expression creates the GroupedEnumerable object. The f...

How to Transform a LINQ Expression when you do not have one of the parameters when you define it.

I'm trying to build more generic query functionality into my application. What I'd like to do is define objects which given an predicate expression can apply that to an iqueryable with a value that will be passed in later. I believe the code below should demonstrate what I'm trying to do well enough to understand the problem. Please let...

Queries generated by group by vs group join

I have the following group by linq statement from c in Categories join p in Products on c equals p.Category into ps select new { Category = new {c.CategoryID, c.CategoryName}, Products = ps }; However this generates the following left outer join query and returns all categories even if there are no products associated. SELECT [t0].[C...

C# Converting set flags in a variable of type flag enumeration to an array of integers

I came up with this piece of code that converts the set flags in a variable of type Flag Enumeration and returns the set flags as integers. I'd like to know if this is the best approach. Example enumeration: [Flags] enum Status { None = 0x0, Active = 0x1, Inactive = 0x2, Canceled = 0x4, Suspended = 0x8 } The extension method...

Access DataContext behind IQueryable

Is it possible to access the DataContext object behind an IQueryable? If so, how? ...

LINQ: Call Stored Procedure and Join its results with IQueryable

I have: a stored procedure which retrieves zip codes in a radius around another zip code a table with contacts I'm getting the contacts through an IQueryable interface which I've extended with various extension methods to filter results by age etc. What I have trouble with is adding an IQueryable extension method which calls the st...