You're looking for a many-to-one relationship in NH lingo. References() in
FNH. You want to map ScmUnit in ElementalBaseline as such.

You don't need a reference back to elemental baseline from ScmUnit.

In terms of how to achieve that with Automapping, might be tricky, but look
at implementing an Automap convention. I'd personally get this going without
automapping first, using the Fluent Interface (where you'd specify
References()).

On Thu, Dec 3, 2009 at 8:35 PM, Tonya <[email protected]> wrote:

> 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]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge

--

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.


Reply via email to