I’m trying to join two tables from DB but I need to join them on specified columns (not on keys).
Tables look like:
EmplTable: Id, EmplId, FirstName, LastName
LoginTable: Id, EmplLoginId, Login
Domain object Employee:
public class Employee
{
public virtual int Id { get; set; }
public virtual String FirstName { get; set; }
public virtual String LastName { get; set; }
public virtual String Login { get; set; }
}
My Mapping looks like:
public EmployeeMap()
{
Table("EmplTable");
Id(x => x.Id).Column("Id");
Map(x => x.FirstName).Column("FirstName");
Map(x => x.LastName).Column("LastName");
Join("LoginTable", m =>
{
m.Fetch.Join();
m.KeyColumn("EmplId");
m.Map(t => t.Login).Column("Login");
});
}
What I’m trying to do is join tables on EmplTable.EmplId=LoginTable.EmplLoginId
How can I change Join column from Id to EmplId
You could map it as a
many-to-oneand map it like this:You would then need to create a Login object with the properties in your
LoginTableEdit:
I don’t think this is currently possible with NHibernate to do this and therefore not possible with Fluent NHibernate.
https://nhibernate.jira.com/browse/NH-1452
https://nhibernate.jira.com/browse/NH-3143