I'm having a problem mapping an entity to Fluent NHibernate .
I have a 1-N relationship with the two tables in the bank having composite keys.
When I try to list my User entity it returns an error, but this happens only when I create the relationship with the entity AccessDepartment
UserMap
public class UsuarioMap : ClassMap<Usuario>
{
public UsuarioMap()
{
CompositeId()
.KeyProperty(x => x.Email, "Usuario")
.KeyReference(x => x.Empresa, "CodEmp")
.KeyProperty(x => x.CodigoFilial, "Filial");
Map(x => x.Nome, "Nome");
Map(x => x.AcessoTodosDepartamentos, "AllDeptos");
Map(x => x.AcessoTodosPedidos, "allPed");
Map(x => x.Email, "email");
Map(x => x.NivelUsuario, "UsrTipo")
.CustomType<NivelUser>();
Table("Usuario");
References<Empresa>(x => x.Empresa, "CodEmp");
References<CentroCusto>(x => x.CentroCusto, "CCusto");
References<Departamento>(x => x.Departamento)
.Column("CodDep");
HasMany<AcessoDepartamento>(x => x.AcessoDepartamentos)
.KeyColumn("AcessoDep");
}
}
AccessMap
public class AcessoDepartamentoMap : ClassMap<AcessoDepartamento>
{
public AcessoDepartamentoMap()
{
CompositeId()
.KeyProperty(x => x.AcessoDep, "AcessoDep")
.KeyReference(x => x.Departamento, "CodDep");
Map(x => x.CodigoFilial, "Filial");
Table("AcessoDep");
References<Departamento>(x => x.Departamento)
.Column("CodDep");
References<Empresa>(x => x.Empresa)
.Column("CodEmp");
}
}
I've tried everything I've ever seen from the searches I've done and nothing so far, but this bug keeps coming back:
Foreign key (FK44A92FD8F30CB372: AccessDep [AccessDep])) must have same number of columns as the referenced primary key (User, CodEmp, Branch])
How can I resolve?