将两个表映射到第三个表Fluent Nhibernate

将两个表映射到第三个表Fluent Nhibernate,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping,fluent-nhibernate-test,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,Fluent Nhibernate Mapping,Fluent Nhibernate Test,我正在研究Nhibernate,我有两个类,分别是Customer和CusotmerRole及其映射(CustomerMap和CustomerRoleMap)。现在我想将这两个表映射到数据库中名为Customer\u CustomerRole\u Mapping的第三个表。表Customer\u CustomerRole\u映射在数据库中有两列,一列是Customer\u Id(主键和ForeignKey与Customer表一起,另一个是CustomerRole\u Id,它也是Customer

我正在研究Nhibernate,我有两个类,分别是Customer和CusotmerRole及其映射(CustomerMap和CustomerRoleMap)。现在我想将这两个表映射到数据库中名为Customer\u CustomerRole\u Mapping的第三个表。表Customer\u CustomerRole\u映射在数据库中有两列,一列是Customer\u Id(主键和ForeignKey与Customer表一起,另一个是CustomerRole\u Id,它也是CustomerRole表的主键和外键。因此我想知道如何将Customer\u CustomerRole\u映射与Customer和CustomerRole映射。我还需要要求为此创建另一个映射,或者我可以映射这些现有的类。提前谢谢

        /* the below is how to do it without a surogatekey on the link table */
        HasManyToMany<CustomerNHEntity>(x => x.MyCustomers) /* I think this is missing on the POCO */
       .Table("Customer_CustomerRole_Mapping")
            .ParentKeyColumns.Add("AbcCustRoleUUID", p => p.UniqueKey("Emp_CustRole_Unique").Index("IX_ABC123"))
            .ChildKeyColumns.Add("AbcCustomerUUID", p => p.UniqueKey("Emp_CustRole_Unique"))
            .Cascade.None()
            ;
代码:

        /* the below is how to do it without a surogatekey on the link table */
        HasManyToMany<CustomerNHEntity>(x => x.MyCustomers) /* I think this is missing on the POCO */
       .Table("Customer_CustomerRole_Mapping")
            .ParentKeyColumns.Add("AbcCustRoleUUID", p => p.UniqueKey("Emp_CustRole_Unique").Index("IX_ABC123"))
            .ChildKeyColumns.Add("AbcCustomerUUID", p => p.UniqueKey("Emp_CustRole_Unique"))
            .Cascade.None()
            ;
客户服务中心:

public class Customer : BaseEntity
{
    private ICollection<ExternalAuthenticationRecord> _externalAuthenticationRecords;
    private ICollection<CustomerRole> _customerRoles;
    private ICollection<ShoppingCartItem> _shoppingCartItems;
    private ICollection<RewardPointsHistory> _rewardPointsHistory;
    private ICollection<ReturnRequest> _returnRequests;
    private ICollection<Address> _addresses;

    /// <summary>
    /// Ctor
    /// </summary>
    public Customer()
    {
        this.CustomerGuid = Guid.NewGuid();
        this.PasswordFormat = PasswordFormat.Clear;
    }

    /// <summary>
    /// Gets or sets the customer Guid
    /// </summary>
    public virtual Guid CustomerGuid { get; set; }

    /// <summary>
    /// Gets or sets the username
    /// </summary>
    public virtual string Username { get; set; }
    /// <summary>
    /// Gets or sets the email
    /// </summary>
    public virtual string Email { get; set; }
    /// <summary>
    /// Gets or sets the password
    /// </summary>
    public virtual string Password { get; set; }

    /// <summary>
    /// Gets or sets the password format
    /// </summary>
    public virtual int PasswordFormatId { get; set; }
    /// <summary>
    /// Gets or sets the password format
    /// </summary>
    public virtual PasswordFormat PasswordFormat
    {
        get { return (PasswordFormat)PasswordFormatId; }
        set { this.PasswordFormatId = (int)value; }
    }
    /// <summary>
    /// Gets or sets the password salt
    /// </summary>
    public virtual string PasswordSalt { get; set; }

    /// <summary>
    /// Gets or sets the admin comment
    /// </summary>
    public virtual string AdminComment { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether the customer is tax exempt
    /// </summary>
    public virtual bool IsTaxExempt { get; set; }

    /// <summary>
    /// Gets or sets the affiliate identifier
    /// </summary>
    public virtual int AffiliateId { get; set; }

    /// <summary>
    /// Gets or sets the vendor identifier with which this customer is associated (maganer)
    /// </summary>
    public virtual int VendorId { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether the customer is active
    /// </summary>
    public virtual bool Active { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether the customer has been deleted
    /// </summary>
    public virtual bool Deleted { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether the customer account is system
    /// </summary>
    public virtual bool IsSystemAccount { get; set; }

    /// <summary>
    /// Gets or sets the customer system name
    /// </summary>
    public virtual string SystemName { get; set; }

    /// <summary>
    /// Gets or sets the last IP address
    /// </summary>
    public virtual string LastIpAddress { get; set; }

    /// <summary>
    /// Gets or sets the date and time of entity creation
    /// </summary>
    public virtual DateTime CreatedOnUtc { get; set; }

    /// <summary>
    /// Gets or sets the date and time of last login
    /// </summary>
    public virtual DateTime? LastLoginDateUtc { get; set; }

    /// <summary>
    /// Gets or sets the date and time of last activity
    /// </summary>
    public virtual DateTime LastActivityDateUtc { get; set; }

    #region Navigation properties

    /// <summary>
    /// Gets or sets customer generated content
    /// </summary>
    public virtual ICollection<ExternalAuthenticationRecord> ExternalAuthenticationRecords
    {
        get { return _externalAuthenticationRecords ?? (_externalAuthenticationRecords = new List<ExternalAuthenticationRecord>()); }
        protected set { _externalAuthenticationRecords = value; }
    }

    /// <summary>
    /// Gets or sets the customer roles
    /// </summary>
    public virtual ICollection<CustomerRole> CustomerRoles
    {
        get { return _customerRoles ?? (_customerRoles = new List<CustomerRole>()); }
        protected set { _customerRoles = value; }
    }

    /// <summary>
    /// Gets or sets shopping cart items
    /// </summary>
    public virtual ICollection<ShoppingCartItem> ShoppingCartItems
    {
        get { return _shoppingCartItems ?? (_shoppingCartItems = new List<ShoppingCartItem>()); }
        protected set { _shoppingCartItems = value; }
    }

    /// <summary>
    /// Gets or sets reward points history
    /// </summary>
    public virtual ICollection<RewardPointsHistory> RewardPointsHistory
    {
        get { return _rewardPointsHistory ?? (_rewardPointsHistory = new List<RewardPointsHistory>()); }
        protected set { _rewardPointsHistory = value; }
    }

    /// <summary>
    /// Gets or sets return request of this customer
    /// </summary>
    public virtual ICollection<ReturnRequest> ReturnRequests
    {
        get { return _returnRequests ?? (_returnRequests = new List<ReturnRequest>()); }
        protected set { _returnRequests = value; }
    }

    /// <summary>
    /// Default billing address
    /// </summary>
    public virtual Address BillingAddress { get; set; }

    /// <summary>
    /// Default shipping address
    /// </summary>
    public virtual Address ShippingAddress { get; set; }

    /// <summary>
    /// Gets or sets customer addresses
    /// </summary>
    public virtual ICollection<Address> Addresses
    {
        get { return _addresses ?? (_addresses = new List<Address>()); }
        protected set { _addresses = value; }
    }

    #endregion
}
        /* the below is how to do it without a surogatekey on the link table */
        HasManyToMany<CustomerNHEntity>(x => x.MyCustomers) /* I think this is missing on the POCO */
       .Table("Customer_CustomerRole_Mapping")
            .ParentKeyColumns.Add("AbcCustRoleUUID", p => p.UniqueKey("Emp_CustRole_Unique").Index("IX_ABC123"))
            .ChildKeyColumns.Add("AbcCustomerUUID", p => p.UniqueKey("Emp_CustRole_Unique"))
            .Cascade.None()
            ;
公共类客户:BaseEntity
{
私有ICollection\u外部身份验证记录;
私人ICollection_customerRoles;
私人ICollection_购物车项目;
私人ICollection_奖励点历史;
私人ICollection返回请求;
专用ICollection\u地址;
/// 
///执行器
/// 
公众客户()
{
this.CustomerGuid=Guid.NewGuid();
this.PasswordFormat=PasswordFormat.Clear;
}
/// 
///获取或设置客户Guid
/// 
公共虚拟Guid CustomerGuid{get;set;}
/// 
///获取或设置用户名
/// 
公共虚拟字符串用户名{get;set;}
/// 
///获取或设置电子邮件
/// 
公共虚拟字符串电子邮件{get;set;}
/// 
///获取或设置密码
/// 
公共虚拟字符串密码{get;set;}
/// 
///获取或设置密码格式
/// 
公共虚拟整数密码格式ID{get;set;}
/// 
///获取或设置密码格式
/// 
公共虚拟密码格式PasswordFormat
{
获取{return(PasswordFormat)PasswordFormatId;}
设置{this.PasswordFormatId=(int)值;}
}
/// 
///获取或设置密码
/// 
公共虚拟字符串PasswordSalt{get;set;}
/// 
///获取或设置管理员注释
/// 
公共虚拟字符串AdminComment{get;set;}
/// 
///获取或设置一个值,该值指示客户是否免税
/// 
公共虚拟布尔IStaxempt{get;set;}
/// 
///获取或设置附属标识符
/// 
公共虚拟int AffiliateId{get;set;}
/// 
///获取或设置与此客户关联的供应商标识符(maganer)
/// 
公共虚拟整数VendorId{get;set;}
/// 
///获取或设置一个值,该值指示客户是否处于活动状态
/// 
公共虚拟布尔活动{get;set;}
/// 
///获取或设置一个值,该值指示客户是否已被删除
/// 
公共虚拟bool已删除{get;set;}
/// 
///获取或设置一个值,该值指示客户帐户是否为系统帐户
/// 
公共虚拟布尔IsSystemAccount{get;set;}
/// 
///获取或设置客户系统名称
/// 
公共虚拟字符串SystemName{get;set;}
/// 
///获取或设置最后一个IP地址
/// 
公共虚拟字符串LastIpAddress{get;set;}
/// 
///获取或设置实体创建的日期和时间
/// 
公共虚拟日期时间CreatedOnUtc{get;set;}
/// 
///获取或设置上次登录的日期和时间
/// 
公共虚拟日期时间?LastLoginDeutc{get;set;}
/// 
///获取或设置上次活动的日期和时间
/// 
公共虚拟日期时间LastActivityDateUtc{get;set;}
#区域导航属性
/// 
///获取或设置客户生成的内容
/// 
公共虚拟ICollection外部身份验证记录
{
获取{return\u externalAuthenticationRecords???(\u externalAuthenticationRecords=new List());}
受保护集{u externalAuthenticationRecords=value;}
}
/// 
///获取或设置客户角色
/// 
公共虚拟ICollection CustomerRoles
{
获取{return\u customerRoles???(\u customerRoles=new List());}
受保护集{u customerRoles=value;}
}
/// 
///获取或设置购物车项目
/// 
公共虚拟ICollection ShoppingCartItems
{
获取{return _shoppingcartimes???(_shoppingcartimes=new List());}
受保护集{u shoppingCartItems=value;}
}
/// 
///获取或设置奖励积分历史记录
/// 
公共虚拟ICollection奖励点历史记录
{
获取{return{rewardPointsHistory???({rewardPointsHistory=new List());}
受保护集{u rewardPointsHistory=value;}
}
/// 
///获取或设置此客户的退货请求
/// 
公共虚拟ICollection返回请求
{
获取{return\u returnRequests???(\u returnRequests=new List());}
受保护集{u returnRequests=value;}
}
/// 
///默认帐单地址
/// 
公共虚拟地址计费地址{get;set;}
/// 
///默认送货地址
/// 
公共虚拟地址ShippingAddress{get;set;}
/// 
///获取或设置客户地址
/// 
公共虚拟ICollection地址
{
获取{返回_地址???(_地址=新列表());}
受保护集{u addresses=value;}
}
#端区
}
CustomerRole.cs:

 public  partial class CustomerRole : BaseEntity
    {
        private ICollection<PermissionRecord> _permissionRecords;
        /// <summary>
        /// Gets or sets the customer role name
        /// </summary>
        public virtual string Name { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer role is marked as free shiping
        /// </summary>
        public virtual bool FreeShipping { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer role is marked as tax exempt
        /// </summary>
        public virtual bool TaxExempt { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer role is active
        /// </summary>
        public virtual bool Active { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer role is system
        /// </summary>
        public virtual bool IsSystemRole { get; set; }

        /// <summary>
        /// Gets or sets the customer role system name
        /// </summary>
        public virtual string SystemName { get; set; }

        /// <summary>
        /// Gets or sets a product identifier that is required by this customer role. 
        /// A customer is added to this customer role once a specified product is purchased.
        /// </summary>
        public virtual int PurchasedWithProductId { get; set; }

        /// <summary>
        /// Gets or sets the permission records
        /// </summary>
        public virtual  ICollection<PermissionRecord> PermissionRecords
        {
            get { return _permissionRecords ?? (_permissionRecords = new List<PermissionRecord>()); }
            protected set { _permissionRecords = value; }
        }
    }
        /* the below is how to do it without a surogatekey on the link table */
        HasManyToMany<CustomerNHEntity>(x => x.MyCustomers) /* I think this is missing on the POCO */
       .Table("Customer_CustomerRole_Mapping")
            .ParentKeyColumns.Add("AbcCustRoleUUID", p => p.UniqueKey("Emp_CustRole_Unique").Index("IX_ABC123"))
            .ChildKeyColumns.Add("AbcCustomerUUID", p => p.UniqueKey("Emp_CustRole_Unique"))
            .Cascade.None()
            ;
公共部分类CustomerRole:BaseEntity
{
私人ICollection许可记录;
/// 
///获取或设置客户角色名称
/// 
公共虚拟字符串名称{get;set;}
/// 
///获取或设置一个值,该值指示客户角色是否标记为免费发货
/// 
公共虚拟bool-FreeShipping{get;set;}
/// 
///获取或设置一个值