linq-to-entities

How to use SQL 'LIKE' with LINQ to Entities?

I have a textbox that allows a user to specify a search string, including wild cards, for example: Joh* *Johnson *mit* *ack*on Before using LINQ to Entities, I had a stored procedure which took that string as parameter and did: SELECT * FROM Table WHERE Name LIKE @searchTerm And then I would just do a String.Replace('*', '%') befor...

Can you compile a LINQ to Entities query that is composed with if statements?

I have a fairly complex LINQ to Entities query I'd like to try compiling because it's a bit slower than I'd like. I build it in a series of steps though. Here's a simple example: public static List<Employee> GetEmployees(EntityContext ctx, bool showTerminated) { var q = ctx.Employees; if(showTerminated==false) { q ...

Does calling Select() or GroupBy() in Linq to entities trigger querying the database?

I have a hard time telling what operations in linq cause a SQL command to be issued to the database. I know calling ToList() or iterating w/ foreach will cause the query to run but do Select and GroupBy cause the code to execute on the database? ...

LINQ to Entities Group By expression gives 'Anonymous type projection initializer should be simple name or member access expression'

I am getting the above mentioned error with this expression: var aggregate = from t in entities.TraceLines join m in entities.MethodNames.Where("it.Name LIKE @searchTerm", new ObjectParameter("searchTerm", searchTerm)) on t.MethodHash equals m.MethodHash where (t.CallTypeId & (int)types) == t.CallTypeId && t.UserSessionProcessId...

Search in a list .Net 3.5 which analagous to SQL - column in ( value1, value2, ... , valuen )

I do have List<ColumnDiff> columnDiffList of public class ColumnDiff { public string columnName; public string leftValue; public string rightValue; } I need to determine whether there are elements where columnName either "A", "B" , "C" It is not essential to extract a subList. In SQL terms colum...

getting a row index from a Linq to Entities query

In a previous post there was mentioned using an overload of the Select method to reference an Index value. This would be exactly what I need to answer this question However, when I try to use this overload as below, I get a NotSupportedException DbObjects.OrderBy (o => o.CreatedOn ).Select((o,i) => new {entity = o, rownumber = i}) I...

Entity framework result discrepancy for a database views

I have one specific view created in my DB(joins about 5-6 tables with a left join).This view is added to my edmx (entity framework 1.0) . Recently I noticed that one of the column records obtained using the edmx (linq to entities and then ToList()) got duplicated multiple times though in the database view they were different Column-N (E...

How to perform Linq to Entites Left Outer Join

I have read plenty of blog posts and have yet to find a clear and simple example of how to perform a LEFT OUTER JOIN between two tables. The Wikipedia article on joins Join (SQL) provides this simple model: CREATE TABLE `employee` ( `LastName` varchar(25), `DepartmentID` int(4), UNIQUE KEY `LastName` (`LastName`) ); CREATE TABLE `depa...

Are LINQ to Entites 4.0 Queries Compiled By Default?

I've just recently started using LINQ on a daily basis. I've read quite a lot about L2E queries should be compiled to improve performance using the following: CompiledQuery.Compile(query); Using LINQ-To-Entities 4.0 I ran a query 10 times uncompiled and then compiled and yielded the following results in seconds: // Sample Query from ...

How to handle Linq to Entity exceptions (errors)?

What is the best way to handle linq to entity exceptions? Can I use try and catch block or is there better way? ...

LINQ-to-Entities get rid of sp_executesql

I am trying to optimize my database now using Database Engine Tuning Advisor, and the problem I am facing is that my SQL Profiler trace shows tons of queries performed using sp_executesql - and the advisor fails to process those. It seems like these queries come from LINQ-to-Entities I am using, so just curious if there is any way to mak...

Linq to Entities in .Net, 4.0, Lazy Loading still eager loading

I'm using Linq to Entities for some simple database access. In the automatically generated entities, there's a Class IndexMeta, which refers to a collection of objects of class IndexData. Although i set the ObjectContext like this: this.xxxDataEntities.ContextOptions.LazyLoadingEnabled = true; It seems the DataEntities is still doin...

Linq-to-Entities ~ When using Include to add a child table, how can I filter on child table properties?

Is there a way to apply Where clauses on to the Included child tables? Example: I have a Customers entity set and and Addresses entity set, and I've appropriately decorated the metadata class with the [Include] attribute. I can easily filter on a property of Customer, such as last name... public IQueryable<Alphagram> GetCustomersWit...

Can Linq to SQL/Linq to Entities generate a MERGE statement?

Looking for a combined INSERT/UPDATE/DELETE statement, MERGE is exactly what I need, but I can't seem to find if LINQ/SQL supports it (from http://www.sqlbook.com/SQL-Server/SQL-MERGE-35.aspx) -- Merge order items into OrderItems table MERGE INTO OrderItem As oi USING @UpdatedItems ui ON (oi.OrderID = ui.OrderID AND oi.ProductID = ui.Pr...

How to choose that which ORM would be feasible for or Application? e.g if we are using Linq then why not hibernate

How to choose that which ORM would be feasible for a web Application? e.g if we are using Linq then why not nhibernate? and Which one is better and why ...

LINQ 2 Entities inverse navigation left join for 0..1-many

New to L2E, found out that I can't use DefaultIfEmpty() until I get L2E 4 (which will hopefully be happening soon). I found an article regarding left joins via inverse navigation, which seems like a clean method for left joins. That said, the article appears to be incorrect, in that the snippet from lPnpItem in PnpItems join lPnpItemVa...

LINQ to Entity Framwework Multiple Joins with Multiple Dynamic Search Criteria

The gist of the problem is that we have an alumni table (one record per person) and also a couple of other tables (one to many) that have degree info and interest info. In a search screen in our app you can search for criteria that spans all three tables (there are actually more fields and tables than shown in the example below but I am...

Concurrency check fails with hierarchical data EF 4.0

Hi. I got a problem with Entity Framework 4.0 I have a hierarchical table Category: Id, Name, ParentCategory_Id, timestamp The "timestamp" field is marked as "Concurrency Mode" = "Fixed" And I'm using Self-Tracking Entity "Category" to manage Category entity in my MVC application. The situation: I create STE "NewCategory", set ...

what ADO.Net version is currenlty used in ASP.net MVC 2?

Hi, Current ASP.Net MVC 2 uses Linq to SQL or Linq to entites? i am using VS 2008. Cheers ...

LINQ2SQL switch to EF on reading a list of records

I am trying to switch from LINQ2SQL to EF ... I am getting the following error with some code that originally worked with LINQ2SQL and seems to compile correctly: Csla.DataPortalException: DataPortal.Fetch failed (LINQ to Entities does not recognize the method 'MyApp.Logic.UserInfo FetchUserInfo(MyApp.Data.User)' method, a...