I have an object Site, like this
public class Site
{
public virtual int SiteId { get; set; }
public virtual Options Options { get; set; }
}
And I have an options object
public class Options
{
public virtual int OptionsId { get; set; }
private int SiteId { get; set; }
private Site Site { get; set; }
}
The caveat here is that I cannot add any fields to the Site
table. In the past, I have done a mapping like this
public class SiteMap : ClassMap<Site>
{
public SiteMap()
{
Table("Sites");
HasOne<Options>(x => x.Options)
.Cascade.All();
}
}
public class OptionsMap : ClassMap<Options>
{
public OptionsMap()
{
Table("Options");
Id(Reveal.Property<Options>("SiteId")).GeneratedBy.Foreign("Site");
HasOne<Site>(Reveal.Member<Options, Site>("Site"))
.Constrained()
.ForeignKey();
}
}
This always worked great. Except one small snaffu - my options table is in a different schema. I have added Schema("MySchema");
to the mapping for my Options
object, but when I try to get a site, I get nothing back. I am pretty sure my problem is the .ForeignKey();
.
How to I map this when the two related objects are in different schemas?