我有一个表保存文件夹信息{Id,FileName,Folder,...} - >让我们称之为文件
1, Presentation, Work\Presentations
2, CV, Private
3, Report, Work
我需要在树形控制中表示这些信息 .
对于上述数据,它将是这样的:
Work //Folder
|->Presentation //Folder
|->Presentation //File
|->Report //File
Private //Folder
|->CV //File
对于这个purpouse我做了一些课程:
TreeNode
{
...some properties
List<TreeNode> Descendants;
}
File : TreeNode
{
...
}
Folder : TreeNode
{
...
}
当我从DbContext读取“文件”数据时,我在列表中生成文件夹文件结构,然后将此列表作为数据源添加到DevExpress TreeList控件
问题是,我只需要在我的EF模型中包含这个“File”POCO类,而不需要基类“TreeNode”中的属性
I tried to configure this by using fluent-api for "File" - >为继承的TreeNode属性添加Ignore(x => x ...) - 但结果证明是不允许的 - >然后我试图找到一种方法将TreeNode POCO类标记为"Not mapped" - 没有成功
Then I thought that maybe Table per concrete Class inheritance could be solution for this (虽然我认为不推荐这种继承类型)
public BaseTypeMapping() //ctor in EntityTypeConfiguration<BaseTypeMapping>
{
.Map<DerivedType>(m=>
{
//commented because I don't need properties from base class in my database
// m.MapInheritedProperties();
m.ToTable("DerivedTypeTable");
}
)
}
在我的DbContext中,我将其定义如下:
public DbSet<TreeNode> Files { get; set; }
当我想从DbContext获取所有文件时,我使用这个:
var autotexts = context.Files.OfType<File>()ToList();
but I get an error "Invalid object name 'dbo.TreeNodes'." 所以我想实体框架也希望这个基类也映射到EF .
Is there a way to make this work?