Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityFramework Core 1.1.0 missing Include()? [duplicate]

I am using EntityFramework Core 1.1.0. I can query a table and load entities, but the instructions from Microsoft indicates if I want to load relational data, I should use the .Include() function:

https://docs.microsoft.com/en-us/ef/core/querying/related-data

You can use the Include method to specify related data to be included in query results. In the following example, the blogs that are returned in the results will have their Posts property populated with the related posts.

using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Include(blog => blog.Posts)
        .ToList();
}

I have no .Include() option.

Any ideas why this is missing or how to load foreign-key relational data?

this.context.Mail
    .Include("Files") // This is missing

I have resorted to explicitly loading relational data. This is fine for small result sets, but as my data sets grow, this is going to cause me grief.

var mails = this.context.Mail.ToList();
mails.ForEach(mail =>
{
    this.context.Entry(mail)              
    .Collection(m => m.Files)
    .Load();
});
like image 378
birwin Avatar asked Feb 07 '17 19:02

birwin


People also ask

Is Entity Framework Core doing an insert instead of update?

[SOLVED] => Entity Framework Core: Update () method INSERTs instead... It seems like EF Core is doing an INSERT instead of an UPDATE, and thus MySQL complains about a duplicate key. However, I am using the Update method on the DbSet and the entities do have primary keys set.

What is the use of include in Entity Framework?

include. In Entity Framework, the Include method loads the related objects to include in the query results. It can be used to retrieve some information from the database and also want to include related entities.

Does entityframeworkcore exist in the namespace?

[SOLVED] => EntityFrameworkCore does not exist in the namespace... I am trying to walk through this tutorial here. However after successfully installing EntityFrameworkCore in the package manager console using the command: Install-Package Microsoft.EntityFrameworkCore.SqlServer

What does Entity Framework dbupdateexception mean?

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries.


1 Answers

Have you included the correct namespaces?

From the repository linked in the documentation:

using Microsoft.EntityFrameworkCore;
using System.Linq;
like image 119
Christian Gollhardt Avatar answered Sep 18 '22 13:09

Christian Gollhardt