EntityFramework Core 1.1.0 missing Include()?

c# entity-framework entity-framework-core

Question

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();
});
1
6
2/7/2017 10:41:00 PM

Accepted Answer

Have you included the correct namespaces?

From the repository linked in the documentation:

using Microsoft.EntityFrameworkCore;
using System.Linq;
23
2/7/2017 10:29:09 PM

Popular Answer

Add the namespace to get that option.

using Microsoft.EntityFrameworkCore;

and also if you haven't added,

using System.Linq;

If you enable the lazy loading then you don't even need to use include.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow