Hi,
I am very new to Fluent NHibernate and ORMs in general. I am having
some trouble creating a one-to-zero-or-one relationship. I'm using
automapping.
Here are the relevant classes:
public class ElementalBaseline : Baseline
{
public virtual ScmUnit ScmUnit { get; protected set; }
public virtual void AddScmUnit(ScmUnit scmUnit)
{
ScmUnit = scmUnit;
scmUnit.ElementalBaseline = this;
}
}
public class ScmUnit
{
public virtual int Id { get; protected set; }
public virtual string Server { get; set; }
public virtual int Port { get; set; }
public virtual string Path { get; set; }
public virtual ElementalBaseline ElementalBaseline { get;
internal protected set; }
}
Here are the relevant tables that are being generated. (I'm using SQL
Server 2008, in case that matters.)
Table: ElementalBaseline
Baseline_id int NOT NULL, --PK. This is OK - it's from the base
class (Baseline)
ScmUnit_id int NULL --Has FK on Id in ScmUnit table
Table: ScmUnit
Id int IDENTITY(1,1) NOT NULL,
Server nvarchar(255) NULL,
Port int NULL,
Path nvarchar(255) NULL,
ElementalBaseline_id int NULL, --Has FK on Baseline_id in
ElementalBaseline table
Just to clarify, an ElementalBaseline should always contain an
ScmUnit, but an ScmUnit could have a null ElementalBaseline.
With that said, I really don't want the ElementalBaseline_id field in
the ScmUnit table. I don't particularly need the ElementalBaseline
property in the ScmUnit class, either, but if I exclude it, the
ScmUnit table apparently isn't even generated.
Any thoughts on what I'm doing wrong here? Or maybe this is as good
as it gets? Is there anyway to at least force
ElementalBaseline.ScmUnit_id to be generated as NOT NULL?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en.