C# PgAdmin导入/导出未保留实体框架的外键
我包括了一大堆信息,但可以跳过标题“问题”来阅读实际问题 介绍 在本地数据库中,我构建了一个表模式,并用数据填充它们 基本流程: 表单表格与问题表格具有一对多关系 问题与答案表有一对多关系C# PgAdmin导入/导出未保留实体框架的外键,c#,postgresql,entity-framework,linq,asp.net-core-webapi,C#,Postgresql,Entity Framework,Linq,Asp.net Core Webapi,我包括了一大堆信息,但可以跳过标题“问题”来阅读实际问题 介绍 在本地数据库中,我构建了一个表模式,并用数据填充它们 基本流程: 表单表格与问题表格具有一对多关系 问题与答案表有一对多关系 public class AppointmentForm { [Key] public long Id { get; set; } public string FormName { get; set; } public int Order { get; set; } p
public class AppointmentForm
{
[Key]
public long Id { get; set; }
public string FormName { get; set; }
public int Order { get; set; }
public List<AppointmentQuestion> Questions { get; set; }
}
public class AppointmentQuestion
{
[Key]
public long Id { get; set; }
[ForeignKey("FormId")]
public virtual AppointmentForm Form { get; set; }
public long FormId { get; set; }
public int Order { get; set; }
public bool? Required { get; set; } = false;
public string Question { get; set; }
public virtual List<AppointmentAnswer> Answers { get; set; }
}
问题表引用了带有FormId的表单表
答案表引用了带有问题ID的问题
以下是表格和问题表格的代码
public class AppointmentForm
{
[Key]
public long Id { get; set; }
public string FormName { get; set; }
public int Order { get; set; }
public List<AppointmentQuestion> Questions { get; set; }
}
public class AppointmentQuestion
{
[Key]
public long Id { get; set; }
[ForeignKey("FormId")]
public virtual AppointmentForm Form { get; set; }
public long FormId { get; set; }
public int Order { get; set; }
public bool? Required { get; set; } = false;
public string Question { get; set; }
public virtual List<AppointmentAnswer> Answers { get; set; }
}
要创建此脚本,我将使用以下脚本(否则所有内容都将被嵌套)
公共异步任务GetModelNormalized()
{
AppointmentModelNormalized Model=新的AppointmentModelNormalized();
名单
您不包括相关对象,请使用以下代码,有关更多信息,请阅读本文档 从Christian4423编辑: 我能够让它对语法做同样的事情
List<AppointmentForm> Forms = await _context.AppointmentForms
.Include("Questions.Answers")
.ToListAsync();
List Forms=wait\u context.AppointmentForms
.包括(“问题、答案”)
.ToListAsync();
您不包括相关对象,请使用以下代码,有关更多信息,请阅读本文档
从Christian4423编辑:
我能够让它对语法做同样的事情
List<AppointmentForm> Forms = await _context.AppointmentForms
.Include("Questions.Answers")
.ToListAsync();
List Forms=wait\u context.AppointmentForms
.包括(“问题、答案”)
.ToListAsync();
f.Questions
为空?请将异常消息放入您的问题中,此问题尚未为我澄清。我将在早上将其抛出。谢谢。我想查看此方法GetAppointFormsAsSync()
codes。让我们看看。f.Questions
为空?请在您的问题中添加异常消息,这个问题没有为我澄清。我会在早上把它吐出来。谢谢。我想看看这个方法getAppointFormsAsync()
codes。让我们看看。
List<AppointmentForm> Forms = await _context.AppointmentForms
.Include("Questions.Answers")
.ToListAsync();