Linq-to-Entities include

I'm currently learning a little about Linq-To-Entities - especially at the moment about impatient and lazy loading.

proxy.User.Include("Role").First(u => u.UserId == userId)

It is supposed to load the user, as well as any roles that the user has. I have a problem, but I also have a question. This is just a simple model designed to learn L2E

I got the impression that this was done in order to make things strong - so why should I write "Role"? It seems that if I changed the name of the table, it would not create a compilation error ...

My mistake is this:

The specified type member 'Roles' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

The solution below allows me to write code:

proxy.User.Include(u => u.Role).First(u => u.UserId == userId)

Which MUCH is better!

+3
source share
1
  • Include - , .
  • IsLoaded, -, , , Include.
  • include, , Entity Framework. Google - : Entity Framework ObjectQueryExtension Include
+5

Source: https://habr.com/ru/post/1720968/


All Articles