linq-to-entities

What statements does Linq to entities support?

Does anyone know where I can get a full list of supported statements for linq to entities, this is statements that will be translated and run on the database...? ...

How to create an Expression Tree to do something similar to the SQL "Like " command

I’m working on some expression tree code written by a colleague and am looking into the possibility of adding additional expressions. It currently supports: equals, not-equals, IsNull etc. I need to add something that will allow it to use a wildcard comparison similar to the SQL “Like” command or using regular expressions. At the moment ...

Can I include stored procs when using edmgen.exe?

I have a couple of scripts I use to generate my edmx files (using edmgen and edmgen2). Is there a way to include stored procs? Or do I have to use the GUI designer for this? ...

Map a stored procedure to an Entity object and its child objects

Within EF4, it's pretty easy to map a stored procedure into an entity. I create the stored proc, Add it to the model, then do a Function Import and specify the parent entity. Now, the rub comes in that I want my stored proc to do "eager loading" of the children entities. In effect, I have a table Parents and a table Children, with a o...

Resolving method overload among LINQ query methods

So, the context of this question is pretty specific, but I think there is a general C# question struggling to get out. :) I have an ASP.NET Web Forms page with a GridView control bound to an ObjectDataSource. The data source control is hooked to a data access class that, in turn, uses LINQ to query Entity Framework v4. The methods on t...

How to return rows with max value one column grouped by another column?

this is data id code status 1 1 5 2 1 6 3 2 8 4 2 9 5 2 12 6 3 15 7 3 19 8 3 13 what I need as a result is this: id code status 2 1 6 5 2 ...

Retreive all Children and their Children, recursive SQL

Consider the following rows in a database: Id | Parent __________________ 1 null 2 1 3 2 4 3 5 null 6 5 Each Id that has a null Parent is the "Owner"/"Super Parent". What would be the best approach, performance wise, to collect the parents and their children ? Shoul...

Linq-to-entities: Easy to find max value in SQL, but difficult in LINQ?

I've started using Linq-to-entities with .NET 3.5, and I've come across a scenario that I can do real easy in SQL, but I'm having great difficulty with linq. I have a table in a SQL database with three fields, for purposes of this example I'll call them foo, bar, and foo_index and populate them like so: Blockquote foo | b...

LINQ to Entities attaching and detaching foreign key entities

I am currently using LINQ and the Entity Framework to do my database connection layer. In my database I have a Files table and a Products table. I also have a ProductHasFiles table that joins the 2 in a many to many relationship. My issue is this. I have a single file loaded in my context and I have a list of Product IDs that I need t...

Enhance this LINQ query for readability and performance?

I'm not the greatest with LINQ, but I'm trying to retrieve all the ModuleAvailabilities where the academicYear is the current year. Are there any improvements to be made here? pathway.PathwayFoundationModule.Attach( pathway.PathwayFoundationModule.CreateSourceQuery() .Include("Module") .Include("Module.ModuleAvaila...

XQuery in Linq To Entities for Sql Server XML Data Type

I am trying to figure out how to do a Linq To Entities query on a SQL Server Database which contains an XML datatype: I want to do a database level query that returns only a specified XML node that contains over 2000 Characters Is this possible in Linq To Entities? Update well i want to do something like this in linq-to-entities bu...

LINQ Having Clause with inner select

How would the following be converted to LINQ-EF select Name from TableA as TableAOuter group by TableAOuter.Name, TableAOuter.Id having( select count(TableAInner.Id) from TableA as TableAInner where TAbleAInner.Reference=TableAOuter.Id) = 0 ); ...

LINQ to Entities does not recognize the method 'Int32

public ActionResult ReadXMLDevices(int groupID) { var query = from k in XMLEntities.unassigneditems where k.DevOrAcc == true && k.Group == groupID select k; var view_query = from i in query select new GetFreeDevices { MArticleNumber = i.Artic...

LINQ: Sorting on many columns dynamically

I have a query of IQueryable and want to apply sorting to it dynamically, sorting can be on many columns (asc or desc). I've written the following generic function: private IQueryable<T> ApplySorting<T,U>(IQueryable<T> query, Expression<Func<T, U>> predicate, SortOrder order) { if (order == SortOrder.Ascending) {...

EntityReference can have no more than one related object.

I have two identical controller actions and two nearly identical views (one just has a different javscript file with it). One view works just fine, but the other gets hung up on this EF error: A relationship multiplicity constraint violation occurred: An EntityReference can have no more than one related object, but the query returned mo...

Linq To Entities (MySql) field lazy loading and/or projection problem

I'm using Linq To Entities so I can Linq to my MySql database. My problem is that I've got a table with large text fields, so I don't want to load them unless I need them, and the L2E lazy loading model doesn't work because (1) the MySql provider doesn't seem to support lazy loading at all, and (2) even if it did, I don't think it would...

Applying a Condition to an Eager Load (Include) Request in Linq to Entities

I have a table Product. Product is related to ProductDescription in a one-to-many relationship. ProductDescription can have more than one row for each product. It will have multiple rows if there are multiple translations for the description of the product. Product has a many-to-one relationship with Language. Language has a language cod...

How can you retrieve all records of certain subtype dynamically with Linq to Entities?

I am trying to get a list of all objects in the database of a specified type. I have done this before when the type was known at compile time, but now I am trying to pass a type into the method and have the method return all the records of that specified type, and I can't get it working. I have tried the following: public IList<W...

EF4, Npgsql, M:M relation, "The method or operation is not implemented." :/

Hello I have a problem with many-to-many relation on EF4 and npgsql provider. I have 3 tables: Order, OrderStatus and OrderStatusDict (dictionary). OrderStatus is some kind of changeLog - every order's status change is added to the OrderStatus table with its actual date and new status. I need to get all orders, which status.OrderStatus...

How Iterate from list of Anonymous Types?

Hi, i have this linq to entities query: c.CreateQuery<T_Hotels>("T_Hotels").Where(item => item.Id > 0).GroupBy(item => new { item.Location, item.Name }).Select(group => new { group.Key, Total = group.Sum(item => item.Id) }) I want to implement everything in a method of a class Helper, how declare the expressions of GroupBy and Select...