我正在为 Orchard CMS 编写模块。
有几张桌子。在 Migrations.cs 中:
它工作正常:
SchemaBuilder.CreateTable("CustomerPartRecord", table => table
.ContentPartRecord()
.Column<string>("FirstName", c => c.WithLength(50))
.Column<string>("LastName", c => c.WithLength(50))
.Column<string>("Title", c => c.WithLength(10))
.Column<DateTime>("CreatedUtc")
);
ContentDefinitionManager.AlterPartDefinition("CustomerPart", part => part
.Attachable(false)
);
ContentDefinitionManager.AlterTypeDefinition("Customer", type => type
.WithPart("CustomerPart")
.WithPart("UserPart")
);
return 6;
但它不起作用:
SchemaBuilder.CreateTable("OrderPartRecord", t => t
.ContentPartRecord()
.Column<int>("CustomerId", c => c.NotNull())
.Column<DateTime>("CreatedAt", c => c.NotNull())
.Column<decimal>("SubTotal", c => c.NotNull())
.Column<string>("Status", c => c.WithLength(50).NotNull())
);
ContentDefinitionManager.AlterPartDefinition("OrderPart", part => part
.Attachable(false)
);
ContentDefinitionManager.AlterTypeDefinition("Order", type => type
.WithPart("OrderPart")
);
尝试添加订单时出现错误。错误:试图从空的一对一属性分配 id:ContentItemRecord出了什么问题?
升级版:
处理程序:
public class OrderPartHandler : ContentHandler
{
public OrderPartHandler(IRepository<OrderPartRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
}
并创建订单:
_orderRepository.Create(order);