Expression does not work in Include in Entity Framework

Asked

Viewed 317 times

0

I tried to make the following expression

var listag = db.grupo.Include(x => x.Itens).ToList();

It doesn’t work that way, but if I pass that way:

db.grupo.Include("Itens").ToList();, So it works, why? What am I doing wrong?

  • Don’t compile that way

  • Which error, using the first way?

  • he doesn’t even recognize the expression in the visual studio

  • Error 5 Cannot Convert lambda Expression to type 'string' because it is not a delegate type

  • It worked well using System.Data.Entity, thank you =)

  • @Tiagosilva Do you want to answer? Just so you don’t open the question.

Show 1 more comment

1 answer

2


The implementation of Include() using a delegate type is in the namespace System.Data.Entity for the Entity Framework case, or System.Linq, if you were using Linq, which is not your case.

As pointed out by @Tiagosilva in comment, check out the header of Controller whether it has the following statements:

using System.Data;
using System.Data.Entity;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.