相关疑难解决方法(0)

WithOptional with Entity Framework Core

我正在尝试将旧的应用程序迁移到新的EF Core,但我找不到像以下这样的关系:

  HasRequired(o => o.Document).WithOptional(o => o.CancelNote);
Run Code Online (Sandbox Code Playgroud)

有一些扩展方法吗?我在文档上找不到.

HasRequired我认为这是可能的替代HasOne()方法,但如何对WithOptional()

另外,根据文档,实体不使用virtual关键字来创建导航属性,延迟加载将如何工作?

entity-framework entity-framework-core .net-core asp.net-core

6
推荐指数
1
解决办法
5921
查看次数

EF Core 中使用 Fluent API 的一对一关系

我在用 EF Core 2.1

如何在 EF Core 中映射一对一关系。我有Customer&Course域实体,其中一位客户将拥有一门课程。

这就是我的 Customer & CoursePOCO 的样子。

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }

}

public class Course
{
    public int Id { get; set; }
    public string CouseName { get; set; }
    public virtual Customer Customer { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 FluentAPI。

 public class CourseConfiguration : IEntityTypeConfiguration<Course>
{
    public void Configure(EntityTypeBuilder<Parent> builder)
    {
        builder.HasKey(x => x.Customer.Id) //not …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core ef-core-2.1 entity-framework-migrations

4
推荐指数
1
解决办法
3161
查看次数