gpt4 book ai didi

c# - 简单的一对多 fluent-nhibernate

转载 作者:行者123 更新时间:2023-11-29 00:32:28 25 4
gpt4 key购买 nike

<分区>

我有简单的一对多关系

public class Product
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual string Category { get; set; }
public virtual bool Discontinued { get; set; }
public virtual IList<ProductCampaignTargeting> Targetings { get; set; }
}

public class ProductCampaignTargeting
{
public virtual Guid ID { get; set; }

public virtual int TargetType { get; set; }

public virtual string TargetValue { get; set; }

public virtual Product Product { get; set; }
}

有映射:

class ProductCampaignTargetingMap : ClassMap<ProductCampaignTargeting>
{
public ProductCampaignTargetingMap()
{
Table("campaign_targetings");
Id(x => x.ID).GeneratedBy.Guid();

Map(x => x.TargetType).Column("target_type");
Map(x => x.TargetValue).Column("target_value");

References(x => x.Product).Column("campaign_id_fk");
}
}

class ProductMap: ClassMap<Product>
{
public ProductMap()
{
Table("Product");
Id(x => x.Id).Column("id").GeneratedBy.Guid();

Map(x => x.Name).Column("Name");
Map(x => x.Category);
// check why inverse doens't work

HasMany(x => x.Targetings).KeyColumn("campaign_id_fk").Cascade.AllDeleteOrphan().AsBag();
}
}

它正在工作 - 但子(许多)表使用两个命令更新 - 插入然后更新当我想将它更改为一个命令时,我使用了 Inverse() 选项——但随后外键被填充为 null,我在这里缺少什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com