C# 每个类型MAPINHERTEDPROPERTIES属性的实体框架表
我在EF中创建了一个模型,其中包含关于网站中包含哪些页面的非常基本的信息:C# 每个类型MAPINHERTEDPROPERTIES属性的实体框架表,c#,entity-framework,C#,Entity Framework,我在EF中创建了一个模型,其中包含关于网站中包含哪些页面的非常基本的信息: namespace Sapphire.Cms.Models { using Sapphire.Cms.Data.Entity; using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; public class Sit
namespace Sapphire.Cms.Models
{
using Sapphire.Cms.Data.Entity;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public class SiteTree
{
public SiteTree()
{
IsHomepage = false;
}
public virtual int SiteTreeId
{
get;
set;
}
[Required]
public string ControllerName
{
get;
set;
}
[Required]
[Index]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings",
Justification = "This is a URL segment, not a complete URL.")]
public string UrlSegment
{
get;
set;
}
[Index]
public bool IsHomepage
{
get;
set;
}
public int ParentId
{
get;
set;
}
}
}
我正在继承SiteTree类以创建SiteTreeHistory类,该类将用于跟踪对SiteTree所做的更改:
namespace Sapphire.Cms.Models
{
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Table("SiteTreeHistory")]
public class SiteTreeHistory : SiteTree
{
public int SiteTreeHistoryId
{
get;
set;
}
[Index]
public override int SiteTreeId
{
get;
set;
}
}
}
我使用的是每类型表属性[表(“SiteTreeHistory”)]
,创建表时,不会创建继承表中的属性
我知道在调用OnModelCreating时可以调用MapInheritedProperties方法,如下所述:
但我找不到具有相同功能的属性,我想知道是否存在一个属性,如果不存在(因为我不太熟悉创建属性),是否可以创建一个属性?我不明白为什么不希望使用MapInheritedProperties方法?从管理角度来看,将与类相关的信息保存在类中比将与如何创建和使用相关的信息分散在各处更有意义。嘿@Bonner,找到答案了吗?厌倦了只为这一种方法创建EF配置了。@Erti ChrisEelmaa不幸的是还没有。