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 theirPosts
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();
});
Have you included the correct namespaces?
From the repository linked in the documentation:
using Microsoft.EntityFrameworkCore;
using System.Linq;
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.