[英]How to configure one-to-one optional relationship with EntityFramework?
[英]How to configure one to one optional relationship with FK
為了限制我們的體系結構,無法更改Id
屬性!
我有一個員工班:
public class Employee
{
public virtual int Id {get; Set; }
public virtual int Matricula {get; Set; }
}
和一個用戶類(系統用戶)
public class User
{
public virtual int Id {get; Set; }
public virtual int Matricula {get; Set; }
public virtual Employee Employee {get; Set; }
}
User
類中的Matricula
屬性應為FK,指向具有Matricula
屬性的Employee
類。
User
類中的Employee
屬性表示與同一Matricula
關聯的Employee對象。
如何通過EF中的Fluent API進行設置?
我們的目標是,如果Matricula
在員工相同的Matricula
在用戶屬性,它們必須被關聯和Employee
類將充滿這名雇員在User
類。
不幸的是,無法使用EF。 對於一對一關系, Matricula
在兩個實體中都應是PRIMARY KEY
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.