I have 2 tables in my database:
- Team Table (Id, Name, WebsiteId (nullable))
- WebSite Table (Id, Name)
A website can be aligned with a team but doesn't have to be. A team can be aligned to a website but doesn't have to. So the relationship between the two is both one or none on either side.
Originally, The only way I could see of doing this is to create a one to many mapping by doing this:
WebsiteMap class
HasMany(x => x.Teams).AsBag().Inverse().Fetch.Select().BatchSize(50);
TeamMap class
References(x => x.WebSite).Nullable();
but to correct enforce a 1:1 mapping, I have to do this in my website class I have this code:
public virtual Team Team
{
get
{
return Teams.FirstOrDefault();
}
}
How can I correctly describe this relationship in the mapping layer itself to avoid having to do this conversion?
The key thing here is that one of these tables is not a slave of the other. All of the examples I see on the internet around 1:1 mappinges with fluent nhibernate assume the second table wouldn't exist without the first (like User table and UserPreferences table) but that is not my situation.
In my example above, since its nullable on both side neither is master or slave?
What is the correct way to map this in fluent nhibernate?