我已经搜索了这个问题的所有内容,但我不确定我的代码有什么问题。如果有人可以帮助我,我将不胜感激。我正在向 uCommerce 7.2.2 添加自定义数据,这意味着通过添加新选项卡来扩展订单详细信息。
为此,我创建了一个这样的新表 -
CREATE TABLE [dbo].[uCommerce_OrderLineItemStatusAudit](
[OrderLineItemStatusAuditId] [int] IDENTITY(1,1) NOT NULL,
[LineOrderStatusId] [int] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[CreatedBy] [nvarchar](50) NOT NULL,
[RefOrderId] [int] NOT NULL,
[Message] [nvarchar](max) NULL,
[Sku] [nvarchar](50) NOT NULL,
PRIMARY KEY CLUSTERED
(
[OrderLineItemStatusAuditId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
实体——
public class OrderLineItemStatusAudit : IEntity
{
public virtual int Id { get; set; }
public virtual int OrderLineItemStatusAuditId { get; set; }
public virtual int LineOrderStatusId { get; set; }
public virtual DateTime CreatedOn { get; set; }
public virtual string CreatedBy { get; set; }
public virtual int RefOrderId { get; set; }
public virtual string Message { get; set; }
public virtual string Sku { get; set; }
}
为表和实体完成的映射 -
public class OrderLineItemStatusAuditMap : BaseClassMap<OrderLineItemStatusAudit>
{
public OrderLineItemStatusAuditMap()
{
Table("uCommerce_OrderLineItemStatusAudit");
Id(x => x.OrderLineItemStatusAuditId, "OrderLineItemStatusAuditId");
Map(x => x.LineOrderStatusId).Not.Nullable();
Map(x => x.Sku).Not.Nullable();
Map(x => x.CreatedOn).Not.Nullable();
Map(x => x.CreatedBy).Not.Nullable();
Map(x => x.RefOrderId).Not.Nullable();
Map(x => x.Message).Nullable();
}
}
这是我得到异常的保存方法 -
private void Save(OrderLine orderLine)
{
orderLine.Save();
var orderLineStatus = new OrderLineItemStatusAudit
{
LineOrderStatusId = 2,
Sku = orderLine.Sku,
CreatedOn = orderLine.CreatedOn,
CreatedBy = "test",
RefOrderId = orderLine.OrderLineId,
Message = null
};
_orderLineItemStatus.Save(orderLineStatus); // **getting exception here - Cannot insert null to LineOrderStatusId column**
}
我已经提到了这个文档 -保存自定义数据
创建映射程序集标签和注册程序集标签也已完成。
任何帮助表示赞赏!
提前致谢。