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
58
votes
7 answers

Is LINQ to SQL deprecated?

Back in late 2008 there was a lot of debate about the future of LINQ to SQL. Many suggested that Microsoft's investments in the Entity Framework in .NET 4.0 were a sign that LINQ to SQL had no future. I figured I'd wait before making my own…
Mayo
  • 10,544
  • 6
  • 45
  • 90
57
votes
1 answer

Problem with LINQ to Entities and String.StartsWith

I'm trying to build a search page using LINQ to Entities, but the following code is giving me a runtime error about l.t.e. not recognising 'Boolean StartsWith(). The code compiles just fine. How can I work around this better than shipping the…
ProfK
  • 49,207
  • 121
  • 399
  • 775
56
votes
11 answers

How do I perform Date Comparison in EF query?

Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query. Example: If I wanted all Employee names for those who started before today, I would do something like this in SQL: SELECT EmployeeNameColumn FROM…
Kam
54
votes
2 answers

C# PredicateBuilder Entities: The parameter 'f' was not bound in the specified LINQ to Entities query expression

I needed to build a dynamic filter and I wanted to keep using entities. Because of this reason I wanted to use the PredicateBuilder from albahari. I created the following code: var invoerDatums = PredicateBuilder.True(); var inner…
Neothor
  • 753
  • 1
  • 5
  • 10
52
votes
5 answers

"NOT IN" clause in LINQ to Entities

Is there anyway I can create a not in clause like I would have in SQL Server in Linq to Entities?
dagda1
  • 26,856
  • 59
  • 237
  • 450
50
votes
8 answers

'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

I am trying to execute the following code and am receiving an error public List GetLoggingData(DateTime LogDate, string title) { var context = new LoggingEntities(); var query = from t in context.Logs where t.Title ==…
mikemurf22
  • 1,851
  • 2
  • 21
  • 32
50
votes
5 answers

How many Include I can use on ObjectSet in EntityFramework to retain performance?

I am using the following LINQ query for my profile page: var userData = from u in db.Users .Include("UserSkills.Skill") .Include("UserIdeas.IdeaThings") …
teenup
  • 7,459
  • 13
  • 63
  • 122
49
votes
2 answers

Is Injection Possible through Dynamic LINQ?

Using the Dynamic LINQ library (link), is it vulnerable to injection? and (if so) how can this be protected against? Some background from Security Considerations (Entity Framework): LINQ to Entities injection attacks: Although query composition is…
Seph
  • 8,472
  • 10
  • 63
  • 94
48
votes
9 answers

How to create LINQ Expression Tree to select an anonymous type

I would like to generate the following select statement dynamically using expression trees: var v = from c in Countries where c.City == "London" select new {c.Name, c.Population}; I have worked out how to generate var v = from c in…
Tom Deloford
  • 2,055
  • 1
  • 23
  • 24
48
votes
5 answers

How to initialize IEnumerable that be empty and allow to Concat to it?
I tried this code for adding b to books: IEnumerable books =null; foreach (Book b in context.Books.AsEnumerable()) if (someConditions) books = books.Concat(new[] {b}); but gives me this error on last line of…
Majid
  • 13,853
  • 15
  • 77
  • 113
47
votes
5 answers

LINQ to Entity : Multiple join conditions

There are numerous post regarding LINQ and multiple joins. I have however not found any solution to the join I'd like to make. The SQL equivalent would be something like this: SELECT * FROM table1 a LEFT JOIN table2 b ON a.col1 = b.key1 AND a.col2 =…
Kman
  • 4,809
  • 7
  • 38
  • 62
47
votes
4 answers

Entity Framework: Querying Child Entities

It seems that I can't get a parent and a subset of its children from the db. For example... db.Parents .Include(p => p.Children) .Where(p => p.Children.Any(c => c.Age >= 5)) This will return all Parents that have a child aged 5+, but if I iterate…
ETFairfax
  • 3,794
  • 8
  • 40
  • 58
47
votes
5 answers

Delete entities without loading them into memory

In Entity Framework Core I have the following Entity: public class File { public Int32 Id { get; set; } public Byte[] Content { get; set; } public String Name { get; set; } } And I have a list of files ids which I need to delete: List
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
47
votes
9 answers

Linq int to string

how do I cast and int into a string? None of the following do works: from s in ctx.Services where s.Code.ToString().StartsWith("1") select s from s in ctx.Services where Convert.ToString(s.Code).StartsWith("1") select s from s in…
pistacchio
  • 56,889
  • 107
  • 278
  • 420
46
votes
3 answers

How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()

I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it) and I'm writing a lot of code like this: var item = (from InventoryItem item in db.Inventory where item.ID == id select…
JC Grubbs
  • 39,191
  • 28
  • 66
  • 75