Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't find "Include" method with lambda expression in Entity framework?

I am using entity framework and I can't find include method like in this example:

using(ArticleExtractorEntities db=new ArticleExtractorEntities())  
{
    Preference pref= db.Preferences.Include(  

here i find only the function include with the parameter (string path) and I don't find any other overload so how can I use Include with lambda expression?

like image 388
Ahmad Houri Avatar asked Jun 29 '12 09:06

Ahmad Houri


People also ask

What is lambda expression in Entity Framework?

The term 'Lambda expression' has derived its name from 'lambda' calculus which in turn is a mathematical notation applied for defining functions. Lambda expressions as a LINQ equation's executable part translate logic in a way at run time so it can pass on to the data source conveniently.

What is find method in Entity Framework?

The Find method on DbSet uses the primary key value to attempt to find an entity tracked by the context. If the entity is not found in the context then a query will be sent to the database to find the entity there. Null is returned if the entity is not found in the context or in the database.

What is include in LINQ query C#?

LINQ include helps out to include the related entities which loaded from the database. It allows retrieving the similar entities to be read from database in a same query. LINQ Include() which point towards similar entities must read from the database to get in a single query.

What is the use of lambda expression in C#?

Lambda expressions and tuples The C# language provides built-in support for tuples. You can provide a tuple as an argument to a lambda expression, and your lambda expression can also return a tuple. In some cases, the C# compiler uses type inference to determine the types of tuple components.


2 Answers

it's not in System.Linq. Add

using System.Data.Entity
like image 66
Raphaël Althaus Avatar answered Nov 06 '22 13:11

Raphaël Althaus


Update. For those looking how it extend your linq query with .Include()

No longer is it:

using System.Data.Entity;

With netcoreapp1.0 it is:

using Microsoft.EntityFrameworkCore;
like image 12
Easton James Harvey Avatar answered Nov 06 '22 13:11

Easton James Harvey