在 Orchard 中,我有一个模型调用MachineRecord
了一些属性并且一切正常,但现在我添加了一个属性,DateAdded
当我向数据库添加一些示例数据时,所有值都被发布,除了我后来添加的属性。
机器记录.cs
public class MachineRecord
{
public virtual int Id { get; set; }
public virtual GroupRecord GroupRecord { get; set; }
public virtual int MachineNumber { get; set; }
public virtual string Title { get; set; }
public virtual string Description1 { get; set; }
public virtual string Description2 { get; set; }
public virtual string Description3 { get; set; }
public virtual string Description4 { get; set; }
public virtual string Description5 { get; set; }
public virtual string Description6 { get; set; }
public virtual int SerialNumber { get; set; }
public virtual string PriceType { get; set; }
public virtual decimal Price { get; set; }
public virtual int Year { get; set; }
public virtual DateTime DateAdded { get; set; }
}
正如我所说,在这里我添加了一些示例数据,在添加该属性之前它一切正常。
public void AddItems()
{
GroupRecord groupRecord = new GroupRecord()
{
Name = "Grondbewerking"
};
groupRepository.Create(groupRecord);
MachineRecord machineRecord = new MachineRecord()
{
GroupRecord = groupRecord,
Title = "Hassia zaaimachine",
MachineNumber = 100000,
Description1 = "25 Pijpen",
Description2 = "Traploos",
Description3 = "Mech. markeurs",
Description4 = "Max. 30 pijpen",
Description5 = "+ na egje",
Description6 = "Ongecontroleerd",
SerialNumber = 100001,
Price = 1600.00m,
PriceType = "Marge",
Year = 2005,
DateAdded = new DateTime(2012, 11, 9)
};
machineRepository.Create(machineRecord);
}
所以我进入了代码,最后我找到了一个出错的方法,正如我们在这里看到的那样,值和属性实际上是在实体中,所以没关系,但是当我查看其他参数时,propertyNames
比如您可以在这里看到它包含所有属性名称,例如DateAdded
!因此,我进一步查看了最后生成的 SQL Query,该属性不在其中,因此数据库单元格中填充了NULL
.
我确保 db 列的数据类型是datetime
,并且我删除了 mappings.bin 以便 NHibernate 会再次缓存所有属性,但没有结果。
编辑:
忘记发布我的 migrations.cs。
迁移.cs
public class Migrations : DataMigrationImpl
{
public int Create()
{
SchemaBuilder.CreateTable("MachineRecord", table => table
.Column<int>("Id", c => c.PrimaryKey().Identity())
.Column<int>("GroupRecord_Id")
.Column<int>("MachineNumber", c => c.NotNull())
.Column<string>("Title", c => c.NotNull().WithLength(40))
.Column<string>("Description1", c => c.WithLength(70))
.Column<string>("Description2", c => c.WithLength(70))
.Column<string>("Description3", c => c.WithLength(70))
.Column<string>("Description4", c => c.WithLength(70))
.Column<string>("Description5", c => c.WithLength(70))
.Column<string>("Description6", c => c.WithLength(70))
.Column<string>("SerialNumber", c => c.WithLength(6))
.Column<string>("PriceType", c => c.NotNull())
.Column<decimal>("Price", c => c.NotNull())
.Column<int>("Year", c => c.WithLength(4))
.Column<DateTime>("DateAdded", c => c.WithType(DbType.DateTime))
);
SchemaBuilder.CreateTable("GroupRecord", table => table
.Column<int>("Id", c => c.PrimaryKey().Identity())
.Column<string>("Name")
);
return 1;
}
}
有谁知道如何解决这一问题?提前致谢!