0
votes

I have 3 tables:

Table: Company, Columns: Id, Name


Table: User, Columns: Id, Name, CompanyId


Table: CompanyOwnerInfo, Column: Id, CompanyId, OwnerName.....


CompanyId column in both User and CompanyOwnerInfo tables are mapping to Company.Id

My question is how to create a One-to-One mapping for User and CompanyOwnerInfo table without Company table involved? because when I use User object to getting CompanyOwnerInfo there is no necessary to join the Company table?

1

1 Answers

1
votes
public UserMap()
{

    References(x => x.Company, "CompanyId");

    References(x => x.CompanyOwnerInfo, "CompanyId")
        .PropertyRef(compOwner => compOwner.Company)
        .Fetch.Join()
        .Not.LazyLoad()   // if needed
        .ReadOnly();      // important otherwise you have Exception on save because both References want to write to the same column
}