Questions tagged [linq-to-entities]

This tag is for questions about LINQ to Entities, which means LINQ queries using the ADO.NET Entity Framework. Note that this is different than LINQ to SQL or other LINQ providers.

This tag is for questions about LINQ to Entities, which means LINQ queries using the ADO.NET Entity Framework. Note that this is different than LINQ to SQL or other LINQ providers.

Related Links

6860 questions
23
votes
2 answers

From BinaryExpression to Expression>

Suppose I have something like Expression> left = x => x.SomeDateProperty; Expression> right = x => dateTimeConstant; var binaryExpression = Expression.GreaterThan(left,…
pinkfloydhomer
  • 873
  • 3
  • 9
  • 16
22
votes
2 answers

Confused about passing Expression vs. Func arguments

I'm having some trouble understanding the differences between how Expressions and Funcs work. This problem turned up when someone changed a method signature from: public static List ThingList(Func aWhere) To public static…
Erix
  • 7,059
  • 2
  • 35
  • 61
22
votes
5 answers

Why is my SQL Server ORDER BY slow despite the ordered column being indexed?

I have an SQL query (generated by LINQ to Entities) which is roughly like the following: SELECT * FROM [mydb].[dbo].[employees] JOIN [mydb].[dbo].[industry] ON jobs.industryId = industry.id JOIN [mydb].[dbo].[state] ON jobs.stateId =…
George
  • 2,110
  • 5
  • 26
  • 57
22
votes
7 answers

Calling user defined functions in Entity Framework 4

I have a user defined function in a SQL Server 2005 database which returns a bit. I would like to call this function via the Entity Framework. I have been searching around and haven't had much luck. In LINQ to SQL this was obscenely easy, I would…
Evil Pigeon
  • 1,887
  • 3
  • 23
  • 31
22
votes
4 answers

The method 'Skip' is only supported for sorted input in LINQ to Entities

What could be causing this problem? public ActionResult Index(int page = 0) { const int pageSize = 3; var areas = repo.FindAllAreas(); var paginatedArea = new PaginatedList(areas, page, pageSize); return…
Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254
22
votes
4 answers

Use Entity framework I want to include only first children objects and not child of child(sub of sub)

Useing Entity framework I want to include an only the first level of children objects and not the children of child I have these two classes: public class BusinessesTBL { public string ID { get; set; } public string FirstName { get; set; } …
22
votes
2 answers

How to handle error "method 'First' can only be used as a final query operation"

I want to retrieve data from the database in different tables by relation, but I get an error that I don't know how to handle. int customer_id = int.Parse(this.comboBoxnamecustomer.SelectedValue.ToString()); a = (from c in db.Invoices where…
Dana Ali
  • 261
  • 1
  • 2
  • 5
22
votes
1 answer

Entity Framework with Linq, inner Join, Group By, Order By

I have a SQL Query select Firma.Name as companyName, Taetigkeit.Taetigkeit as skillName, SUM(Zeit) as time from Zeiterfassung inner join Firma On ZEiterfassung.FirmenID = Firma.ID inner join Taetigkeit on…
Markus_DE_HH
  • 1,061
  • 3
  • 13
  • 29
21
votes
2 answers

Joining three tables and using a left outer join

I have three tables. Two of them join equally but one will need to join with a left. I'm finding a lot of code to do this in linq but between two tables only. Here is the SQL code that I'm trying to re-code within LINQ. SELECT PRSN.NAME …
MdeVera
  • 647
  • 5
  • 8
  • 22
21
votes
1 answer

Convert String to Int in EF 4.0

Is there any way of doing this at all? I have a string field in the DB and I want to parse it into a int property in my LINQ query (yes, it must be at the IQueryable level, not in memory). I know 2 years ago EF 1.0 couldn't do this (even though LINQ…
Jeff
  • 35,755
  • 15
  • 108
  • 220
21
votes
6 answers

The type appears in two structurally incompatible initializations within a single LINQ to Entities query

I'm trying to build something like conditional queries to get only needed data from the underlying database. Currently I have the following query (which works fine) var eventData = dbContext.Event.Select(t => new { Address = true ? new…
KingKerosin
  • 3,639
  • 4
  • 38
  • 77
21
votes
6 answers

Retrieve only base class from Entity Framework

If I have three classes in entity framework. class Base {} class Left : Base {} class Right : Base {} and I call DBContext.Bases.ToList(); This returns all instances of Base fully typed into their associated inherited types, as some people have…
James
  • 2,458
  • 3
  • 26
  • 50
21
votes
1 answer

LINQ can't use string.contains?

This is my code: string queryString = "Marco".ToLower(); utenti = db.User.Where(p => queryString.Contains(p.Nickname.ToLower()) || queryString.Contains(p.Nome.ToLower()) || …
markzzz
  • 47,390
  • 120
  • 299
  • 507
20
votes
7 answers

How to do a "where in values" in LINQ-to-Entities 3.5

Does anybody know how to apply a "where in values" type condition using LINQ-to-Entities? I've tried the following but it doesn't work: var values = new[] { "String1", "String2" }; // some string values var foo = model.entitySet.Where(e =>…
Ty.
  • 2,220
  • 1
  • 15
  • 14
20
votes
7 answers

Linq to Entity with multiple left outer joins

I am trying to understand left outer joins in LINQ to Entity. For example I have the following 3 tables: Company, CompanyProduct, Product The CompanyProduct is linked to its two parent tables, Company and Product. I want to return all of the Company…
Bob