I'm afraid that I'm having a similar problem, except that I'm using
the
automap.  To get around it, for the time being, I just made the FK
nullable in the database.  All of the values are saved and no error.
If I find a better solution, I'll let you know.

On Feb 17, 2:38 am, BjartN <[email protected]> wrote:
> I have a Vessel object that has a one-to-many relationship with a
> VesselDetail object. When I add a VesselDetail object to the Vessel
> object and try to save the Vessel object, it seems NHibernate does not
> add the foreign key when inserting the VesselDetail object.
>
> Where am I going wrong here ? I just cannot figure it out. Guess Im
> missing some nhibernate / fluent nhibernate skillz here:
>
> Error message:
> BDN.FindVessel.Tests.Integration.NhibernateRepositoryTests.SaveVessel_ShouldAddDetailsToDb_WhenAddedToEntity:
> NHibernate.Exceptions.GenericADOException : could not insert:
> [BDN.FindVessel.Domain.VesselDetail][SQL: INSERT INTO BoatsDetails
> (SaftyGear, OtherMachineryAndGear, Material, Size, Various,
> TranslatorId, SpeenAndConsumption, MainMachinery, Created, Class,
> Capasities, Culture, Interior, Electronics, DeckGear) VALUES
> (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY
> ()]
>   ----> System.Data.SqlClient.SqlException : Cannot insert the value
> NULL into column 'BoatId', table 'FindVesselTest.dbo.BoatsDetails';
> column does not allow nulls. INSERT fails.
> The statement has been terminated.
>
> public class Vessel
> {
>         public virtual int BoatId { get; set; }
>         public virtual IList<VesselDetail> Details { get; set; }
>         //...
>
> }
>
> public class VesselDetail
> {
>         public virtual int VesselDetailId { get; set; }
>         //some other properties
>         //..
>
> }
>
> public class VesselMap: ClassMap<Vessel>
> {
>     public VesselMap()
>     {
>         WithTable("Boats");
>
>         Id(x => x.BoatId, "Id");
>
>         //..
>
>         HasMany(x => x.Details)
>             .WithKeyColumn("BoatId") //foreign key in the BoatsDetails
> table
>             .Cascade.All();
>     }
>
> }
>
> public class VesselDetailMap:ClassMap<VesselDetail>
> {
>   public VesselDetailMap()
>   {
>       WithTable("BoatsDetails");
>
>       Id(x => x.VesselDetailId, "Id");
>
>       //...
>   }
>
> }

--~--~---------~--~----~------------~-------~--~----~
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