EF不回馈课程

Stu*_*urf 0 c# entity-framework asp.net-core-mvc

如果我做:

var organisationList = _context.OrganisationCategory.ToList();
Run Code Online (Sandbox Code Playgroud)

它只返回没有组织和类别的列表.它没有回馈组织和类别模型,而是我得到一个列表:

1, null, null
2, null, null
3, null, null
Run Code Online (Sandbox Code Playgroud)

我想我弄错了?在数据库中是组织的ID和正确设置的类别.

OrganisationCategory模型:

public class OrganisationCategory
{
    public int ID { get; set; }
    public Organisation Organisation { get; set; }
    public Category Category { get; set; }

    public OrganisationCategory() { }

    public OrganisationCategory(Organisation Organisation, Category Category)
    {
        this.Organisation = Organisation;
        this.Category = Category;
    }
}
Run Code Online (Sandbox Code Playgroud)

ApplicationDbContextMOdelSnapshot.cs:

        modelBuilder.Entity("Implicietmeten.Models.Organisations.Categories.OrganisationCategory", b =>
            {
                b.Property<int>("ID")
                    .ValueGeneratedOnAdd();

                b.Property<int?>("CategoryID");

                b.Property<int?>("OrganisationID");

                b.HasKey("ID");
            });
Run Code Online (Sandbox Code Playgroud)

Yur*_* N. 6

实体框架核心仍然不支持延迟加载,因此您只能使用这样的预先加载:

var organisationList = _context.OrganisationCategory.Include(x => x.Organization).Include(x => x.Category).ToList();
Run Code Online (Sandbox Code Playgroud)