I'm writing the module for Orchard CMS.
There are several tables. In Migrations.cs:
It works fine:
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;
But it doesn't work:
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")
);
There's error when I try to add Order. Error: attempted to assign id from null one-to-one property: ContentItemRecord What's wrong?
UPD:
Handler:
public class OrderPartHandler : ContentHandler
{
public OrderPartHandler(IRepository<OrderPartRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
}
And creating Order:
_orderRepository.Create(order);