c# - 实体框架从非抽象类继承表结构,但创建所有字段
问题描述
我有几个表以下列方式声明
[Table("FileDataQuestions")]
public class QuestionFileData : FileData
{
}
FileData 在 DevExpress.Persistent.BaseImpl.EF
这些表使用单个 Id 列创建,但我希望它们使用从 FileData 继承的所有字段创建
我不能使 FileData 抽象,因为它不是我的代码。FileData 被声明为
public class FileData : IFileData, IEmptyCheckable, IObjectSpaceLink, INotifyPropertyChanged
上下文类是
using DevExpress.ExpressApp.Design;
using DevExpress.ExpressApp.EFCore.Updating;
using DevExpress.Persistent.BaseImpl.EF;
using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy;
using Microsoft.EntityFrameworkCore;
namespace Exambuddy2.Module.BusinessObjects
{
[TypesInfoInitializer(typeof(Exambuddy2ContextInitializer))]
public class Exambuddy2EFCoreDbContext : DbContext
{
public Exambuddy2EFCoreDbContext(DbContextOptions<Exambuddy2EFCoreDbContext> options) : base(options)
{
}
public DbSet<ModuleInfo> ModulesInfo { get; set; }
public DbSet<ModelDifference> ModelDifferences { get; set; }
public DbSet<ModelDifferenceAspect> ModelDifferenceAspects { get; set; }
public DbSet<PermissionPolicyRole> Roles { get; set; }
public DbSet<PermissionPolicyUser> Users { get; set; }
public DbSet<FileData> FileData { get; set; }
public DbSet<ReportDataV2> ReportDataV2 { get; set; }
public DbSet<Source> Sources { get; set; }
public DbSet<CourseUnit> CourseUnits { get; set; }
public DbSet<Topic> Topics { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Answer> Answers { get; set; }
protected override void OnModelCreating(ModelBuilder mb)
{
base.OnModelCreating(mb);
mb.Entity<Topic>().HasOne(b => b.CourseUnit).WithMany(i => i.Topics);
mb.Entity<Source>().HasOne(b => b.Topic).WithMany(i => i.Sources);
mb.Entity<Question>().HasOne(b => b.Source).WithMany(i => i.Questions);
mb.Entity<Answer>().HasOne(b => b.Question).WithMany(i => i.Answers);
}
}
}
解决方案
当我将上下文代码粘贴到问题中时,我看到了我的错误。需要为 FileDataQuestions 创建 DbSet 并为 FileData 删除
推荐阅读
- javascript - 在 JavaScript 数组中更新现有变量
- java - Java 程序在 eclipse 中运行。作为可运行的 Jar 失败
- javascript - Twitter API:媒体/上传 400 错误请求:媒体类型无法识别
- java - Java中的随机类型对象总是给我相同的数字
- typescript - TypeScript 定义文件的分发
- bluej - BlueJ 中的刽子手
- react-native - React Native asyncstorage 以保存按钮的样式
- sql - XML 导入 SQL Server 的噩梦
- java - 为什么使用 webflux 进行 spring boot 测试会忽略自定义 jackson 模块
- javascript - 等待所有异步请求在循环内完成