为了账号安全,请及时绑定邮箱和手机立即绑定

克隆对象并将克隆保存到db会导致原始对象丢失关系数据

克隆对象并将克隆保存到db会导致原始对象丢失关系数据

C#
绝地无双 2021-06-30 14:59:34
当我尝试克隆一个Product-object 并将克隆保存到数据库时,原始对象会丢失它的所有关系数据,例如ProductPropertyOptionForProducts,IdentifierForProducts和InCategories。这是产品型号:public class Product{    public int Id { get; set; }    public int ProductGroupId { get; set; }    public int ProductGroupSortOrder { get; set; }    [Required, MaxLength(30), MinLength(4)]     public string Title { get; set; }    [MaxLength(200)]                            public string Info { get; set; }    [MaxLength(4000)]                           public string LongInfo { get; set; }    [Required, DataType(DataType.Currency)]     public decimal Price { get; set; }                                                public int Weight { get; set; }                                                public int ProductTypeId { get; set; }    public ICollection<ProductImage> Images { get; set; }    // Selected property options for this product    public ICollection<PropertyOptionForProduct> ProductPropertyOptionForProducts { get; set; }    // A product can have multiple identifiers (EAN, ISBN, product number, etc.)    public ICollection<IdentifierForProduct> IdentifierForProducts { get; set; }    public ProductType Type { get; set; }    public ICollection<FrontPageProduct> InFrontPages { get; set; }    public ICollection<ProductInCategory> InCategories { get; set; }}一些相关模型:public class ProductInCategory// A linking table for which products belongs to which categories{    public int Id { get; set; }    public int ProductId { get; set; }    public int ProductCategoryId { get; set; }    public int SortOrder { get; set; }    // Nav.props.:    public Product Product { get; set; }    public ProductCategory ProductCategory { get; set; }}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 95 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信