相关疑难解决方法(0)

关联的主要结尾在实体框架中以1:1的关系表示什么

public class Foo
{
    public string FooId{get;set;}
    public Boo Boo{get;set;}
}


public class Boo
{
    public string BooId{get;set;}
    public Foo Foo{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

当我收到错误时,我试图在Entity Framework中执行此操作:

无法确定类型"ConsoleApplication5.Boo"和"ConsoleApplication5.Foo"之间关联的主要结束.必须使用关系流畅API或数据注释显式配置此关联的主要结尾.

我已经在StackOverflow上看到了有关此错误的解决方案的问题,但我想了解术语"主要结束"的含义.

c# database-design entity-framework foreign-key-relationship

266
推荐指数
3
解决办法
12万
查看次数

首先通过Fluent API在EF代码中实现Zero或One to Zero或One关系

我有两个POCO课程

public class Order
{
    int id;
    string code;
    int? quotationId;  //it is foreign key
    public int Id{get;set;}
    public string Code{get;set;}
    public int? QuotationId{get;set;}
    Quotation quotation;
    public virtual Quotation Quotation { get; set; }
    ....
}

public class Quotation
{
    int Id;
    string Code;
    public int Id{get;set;}
    public string Code{get;set;}
    Order order;
    public virtual Order Order { get; set; }
    ....   
}
Run Code Online (Sandbox Code Playgroud)

每个订单可以由一个或零引号组成,每个报价可能会导致一个订单,所以我有一个"一个或零"到"一个或零"关系,我怎么能在EF代码中首先通过流畅的API实现它?

c# entity-relationship entity-framework fluent ef-code-first

35
推荐指数
4
解决办法
4万
查看次数

无法确定类型之间关联的主要结束

我收到这个错误:

无法确定CustomerDetail和Customer类型之间关联的主要结束.

这是我CustomerCustomerDetail模特

[Table("CUSTOMER")]
public class Customer
{
    [Required]
    [Column("CUSTOMER_ID")]
    public int Id {get; set;}

    [Column("FIRST_NAME")]
    public string FirstName {get; set;}
    // other fields  

    public virtual CustomerDetail customerDetail {get; set;}
}

[Table("CUSTOMER_DETAIL")]
public class CustomerDetail
{
    [Required]
    [Column("CUSTOMER_DETAIL_ID")]
    public int Id {get; set;}
    // other fields

    public virtual Customer Customer {get; set;} 
}
Run Code Online (Sandbox Code Playgroud)

CustomerCustomerDetail了1:1的关系.

c# entity-framework

14
推荐指数
1
解决办法
3万
查看次数