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
我有两个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
我收到这个错误:
无法确定CustomerDetail和Customer类型之间关联的主要结束.
这是我Customer和CustomerDetail模特
[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)
Customer到CustomerDetail了1:1的关系.