我对果园有点陌生。我在这里想要实现的是我的实体之间的关系。所以基本上ApiConfigurationRecord应该有一个ApiParameterRecord 列表。但是当我执行这个动作时,什么都没有被保存。另外,如果它保存,希望它会自动延迟加载它的孩子。顺便说一句,我正在尝试非内容方式(没有 ContentPart 或 ContentPartRecord)。
好的,这些是我的代码:
public class ApiConfigurationRecord
{
public ApiConfigurationRecord()
{
if (Parameters == null)
Parameters = new List<ApiParameterRecord>();
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual IList<ApiParameterRecord> Parameters { get; set; }
}
public class ApiParameterRecord
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class Migrations : DataMigrationImpl
{
public int Create()
{
SchemaBuilder.CreateTable("ApiConfigurationRecord", table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("Name", column=> column.NotNull())
.Column<string>("Description", column => column.WithLength(500))
);
SchemaBuilder.CreateTable("ApiParameterRecord", table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<int>("ApiConfigurationRecord_Id")
.Column<string>("Name", column => column.NotNull())
);
return 1;
}
}
我的控制器动作:
public ActionResult TestInsert()
{
var record = new ApiConfigurationRecord() { Name = "Test 1", Description = "Some descripton" };
record.Parameters.Add(new ApiParameterRecord() { Name = "Param1" });
this.ApiConfigurationRepository.Create(record);
return Content("Inserted");
}