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();
});
[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.
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.
[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
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries.
Have you included the correct namespaces?
From the repository linked in the documentation:
using Microsoft.EntityFrameworkCore;
using System.Linq;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With