我正在使用Code First編寫一個模型,其中包含兩個實體:'Action'和'Permission'。Code First One to One relationship
每個權限都指向了一個Action。 沒有兩個權限可能指向相同的操作。 一個動作可能存在,而不會被許可指向。
操作不應該意識到權限。
我的代碼是:
public Action
{
public Guid Id {get; set;}
public string Name {get; set;}
}
public Permission
{
public Guid Id {get; set;}
public string Name {get; set;}
public Action Action {get; set;}
}
而且,我用流利的API配置權限:
modelBuilder.Entity<Permission>.HasRequired(p => p.Action).WithOptional()
.WillCascadeOnDelete();
當我嘗試刪除的動作,我得到以下錯誤:
"Adding a relationship with an entity which is in the Deleted state is not allowed".
I t先刪除權限,然後刪除操作。對於這一點,我需要獲取給定的動作ID的權限,但我得到這個錯誤:
var permission = (from p in context.Permissions.Include(p => p.Action)
where p.Action.Id == actionId
select p).Single();
"Indexed properties are not supported"
我在做什麼錯?對此進行建模有更好的方法嗎?
謝謝! 尼爾