0
聯合收割機擁有物業給出的是以下類:實體框架的核心:具有繼承
public class Rule
{
public long Id { get; set; }
public string Filter { get; set; }
public RuleAction Action { get; set; }
}
public abstract class RuleAction
{
}
public class RuleAction1 : RuleAction
{
public string Value { get; set; }
}
public class RuleAction2 : RuleAction
{
public decimal Percent { get; set; }
}
我想這些類映射到下面的表格佈局。我使用實體框架核心預覽2.
Table "Rule"
- Id
- Filter
- ActionDiscriminator
- Value // only set if the object in Action is typeof(RuleAction1)
- Percent // only set if the object in Action is typeof(RuleAction2)
重要的是「行動」不映射到一個單獨的表。我知道我可以將該財產映射爲本文(OwnsOne)中所述的「擁有財產」:https://blogs.msdn.microsoft.com/dotnet/2017/06/28/announcing-ef-core-2-0-preview-2/,但這種情況似乎與繼承結合使用,至少我找不到示例。
任何人都知道如何將擁有的屬性和繼承結合起來?
擁有的類型不支持繼承。 – Smit