Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么schemaexport会生成2个外键?_C#_Sql Server_Fluent Nhibernate - Fatal编程技术网

C# 为什么schemaexport会生成2个外键?

C# 为什么schemaexport会生成2个外键?,c#,sql-server,fluent-nhibernate,C#,Sql Server,Fluent Nhibernate,我正在SQL Server 2008上使用fluentnhibernate 我必须反对工作人员 public class Staff : BaseEntity { public virtual string UserName { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public virtual s

我正在SQL Server 2008上使用fluentnhibernate

我必须反对工作人员

public class Staff : BaseEntity
{
    public virtual string UserName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual string Email { get; set; }
    public virtual bool Active { get; set; }
    public virtual StaffRole StaffRole { get; set; }
}
员工角色

public class StaffRole : BaseEntity
{
    public virtual int RoleId { get; set; }
    public virtual int RoleName { get; set; }
    public virtual IList<Staff> Staffs { get; set; }
}
公共类StaffRole:BaseEntity
{
公共虚拟int RoleId{get;set;}
公共虚拟整型角色名{get;set;}
公共虚拟IList{get;set;}
}
并相应地绘制了它们:

public class StaffRoleMap : ClassMap<StaffRole>
{
    public StaffRoleMap()
    {
        Id(x => x.RoleId).Not.Nullable().Length(15);
        Map(x => x.RoleName).Not.Nullable().Length(75);
        HasMany(x => x.Staffs);
    }
}
public class StaffMap : ClassMap<Staff>
{
    public StaffMap()
    {
        Id(x => x.UserName).Not.Nullable().Length(15);
        Map(x => x.FirstName).Not.Nullable().Length(25);
        Map(x => x.LastName).Not.Nullable().Length(25);
        Map(x => x.Email).Not.Nullable().Length(30);
        Map(x => x.Active).Not.Nullable().Default("1");
        References(x => x.StaffRole)
            .ForeignKey("FKStaffRole")
            .Column("RoleId")
            .Cascade.None()
            .Not.Nullable()
            ;
    }
}
公共类StaffRoleMap:ClassMap
{
公共员工角色映射()
{
Id(x=>x.RoleId).Not.Nullable().Length(15);
Map(x=>x.RoleName).Not.Nullable().Length(75);
有许多(x=>x.staff);
}
}
公共类StaffMap:ClassMap
{
公共员工地图()
{
Id(x=>x.UserName).Not.Nullable().Length(15);
Map(x=>x.FirstName).Not.Nullable().Length(25);
Map(x=>x.LastName).Not.Nullable().Length(25);
Map(x=>x.Email).Not.Nullable().Length(30);
Map(x=>x.Active).Not.Nullable().Default(“1”);
引用(x=>x.StaffRole)
.ForeignKey(“FKStaffRole”)
.列(“RoleId”)
.Cascade.None()
.Not.Nullable()
;
}
}
当我调用schemaexport时,为什么它会为StaffRole生成2个外键?我总是得到角色id员工角色id。RoleId是正确的,因为它不可为null,但额外列/fk可为null

我是不是遗漏了什么?

是的。必须在关系的一侧设置“反向”。这相当于在常规nhibernate xml配置中设置inverse=true

是的。必须在关系的一侧设置“反向”。这相当于在常规nhibernate xml配置中设置inverse=true