我在尝试保存一些数据时遇到问题。我想要做的是,我有订单,我有一份已经履行并付款的订单。但是,订单类型错误且需要更改,但这样做可能意味着增值税无法添加到订单中,因此需要计算调整以向客户提供资金或让客户付款。所以我的想法是,当在现有的付费订单上更改订单类型时,我创建订单的副本,因此SQL数据库中的另一行(订单表)具有相同的详细信息,创建项目(项目表)的副本在订单中。但是,订单表中的订单类型将有所不同。但是,当我尝试这样做时,我收到了错误
多重约束违反了角色' _关系的目标有多重性1或0..1
用户在屏幕上打开订单,从会话中检索订单详细信息并存储......
public void Save()
{
App_Order form;
List<App_Items> itemsInSession;
...
try
{
form = (App_Order)Session["Form" + id];
itemsInSession = (List<App_Items>)Session["FormDrugItems" + id];
}
// some validation is done
if(orderTypeChanged == true)
{
App_Order duplicateOrder = new App_Order();
duplicateOrder = CreateDuplicateOrderForm(form);
_orderService.SaveForm(duplicateOrder);
}
}
...
public App_Order CreateDuplicateOrderForm(App_Order form)
{
App_Order newForm = new App_Order()
{
OrderType = form.orderType,
OrderDate = form.orderDate,
CustomerId = form.customerId,
}
newForm.App_Items = new List<App_Items>();
foreach(App_Items orderItem in form.App_Item)
{
App_Items item = new App_Items()
{
ItemCode = orderItem.itemCode,
Quantity = orderItem.quantity,
Cost = orderItem.cost
};
newForm.App_Items.Add(item);
}
}
Multiplicity Constraint Violation提到App_Customer具有多重性。它将是来自App_Customer的CustomerId,它存储在CustomerId列的App_Order表中。
关于我做错了什么或我能做些什么来修复它的任何建议?
提前致谢:)
App_Order:
public partial class App_Order
{
[ExcludeFromCodeCoverage]
public App_Order()
{
this.App_PharmacyFormDrugItem = new HashSet<App_PharmacyFormDrugItem>();
}
public int OrderId { get; set; }
public short OrderTypeId { get; set; }
public short OrderDate { get; set; }
public int CustomerId { get; set; }
public Nullable<int> CustomerId_Initial { get; set; }
public virtual Ref_OrderType Ref_OrderType { get; set; }
public virtual Ref_PaymentMonth Ref_PaymentMonth { get; set; }
public virtual App_Customer App_Customer { get; set; }
public virtual App_Customer App_Customer_Initial { get; set; }
public virtual ICollection<App_Item> App_Item { get; set; }
}
App_Customer:
public partial class App_Contract
{
public App_Contract()
{
this.App_CustomerAddress = new HashSet<App_CustomerAddress>();
this.App_CustomerContact = new HashSet<App_CustomerContact>();
}
public int CustomerId { get; set; }
public short CustomerTypeId { get; set; }
public short CustomerSubTypeId { get; set; }
public string Name { get; set; }
public virtual ICollection<App_CustomerAddress> App_CustomerAddress { get; set; }
public virtual ICollection<App_CustomerContact> App_CustomerContact{ get; set; }
public virtual Ref_CustomertSubType Ref_CustomerSubType { get; set; }
public virtual Ref_CustomerType Ref_CustomerType { get; set; }
public virtual ICollection<App_Order> App_Order{ get; set; }
public virtual ICollection<App_Order> App_Order1 { get; set; }
public virtual ICollection<App_Order> App_Order2 { get; set; }
}