希望以前没有人问过这个问题,但这是我的问题。我已经像这样创建了我的模型:
public class Survey
{
public virtual int Id { get; set; }
[Required(ErrorMessage="Survey Name is required")]
[Display(Name="Survey Name")]
public virtual string SurveyName { get; set; }
public virtual bool Disabled { get; set; }
public virtual IEnumerable<Question> Questions { get; set; }
}
public class Question
{
public virtual int Id { get; set; }
public virtual string QuestionText { get; set; }
public virtual int QuestionOrder { get; set; }
public virtual Enums.QuestionType QuestionType { get; set; }
public virtual Survey Survey { get; set; }
public virtual int Survey_Id { get; set; }
}
这反过来又创造了我的迁移:
// Creating table Survey
SchemaBuilder.CreateTable("Survey", table => table
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
.Column("SurveyName", DbType.String)
.Column("Disabled", DbType.Boolean)
);
// Creating table Question
SchemaBuilder.CreateTable("Question", table => table
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
.Column("QuestionText", DbType.String)
.Column("QuestionOrder", DbType.Int32)
.Column("QuestionType", DbType.String)
.Column("Survey_Id", DbType.Int32)
);
我假设 Orchard NHibernate 的工作方式与 EF 相同,因为基于命名约定,我的 Survey 和 Survey_Id 问题的属性映射到数据库中的同一字段(我的迁移会让我相信这是正确的)。
这是我的问题:使用 Orchard 中的 IRepository 在数据库中创建对象会生成如下所示的 sql
INSERT INTO Question (QuestionText, QuestionOrder, QuestionType, Survey_Id, Survey_id) VALUES (?, ?, ?, ?, ?)
哪个错误,因为 Survey_Id 存在两次。
任何帮助或建议都会很棒。