In your vehicles repository, is the .Add(veh1) calling the
session.SaveOrUpdate(veh1)? If so, then is the Vehicle_Id column you're
describing as being empty in the vehicles table or the assets table?

Could you do an .ExportTo() in the config and post the vehicle and asset
mappings that automapper is generating for you? It's possible that it's
setting the collection side as an inverse (in NHibernate lingo it means it
won't save from the parent side of the relationship, it expects the child to
save the association) You might also try doing this as a bi-directional by
adding a reference back to vehicle from asset (although you shouldn't have
to by default).

On Wed, Jun 10, 2009 at 5:27 AM, Sarkie <[email protected]> wrote:

>
> Hi Guys,
>
> Just started a new project and decided I wanted to give Nhibernate a
> try after trying out Entity Framework, I was told by everyone to use
> Fluent instead( as well).
>
> So I am just trying to develop a simple app and I've come across an
> issue with the AutoMapping, reading the Examples.FirstProject it
> *should* work, but I am using AutoMapping rather than manually doing
> it.
>
>
> Here is my Parent - Vehicle:
>
> public class Vehicle
>    {
>        public virtual int Id { get; private set; }
>        public virtual Image Image { get; set; }
>        public virtual Image DrawingImage { get; set; }
>        public virtual string Name { get; set; }
>        public virtual string Description { get; set; }
>
>        public virtual IList<Asset> CurrentAssets {get; private set;}
>
>        public Vehicle()
>        {
>            CurrentAssets = new List<Asset>();
>        }
>
>
>        public virtual void AddAsset(Asset asset)
>        {
>            CurrentAssets.Add(asset);
>        }
>
>
>    }
>
> Here is my Child - Asset
>
> public class Asset
>    {
>        public virtual int Id { get; private set; }
>        public virtual string Name { get; set; }
>        public virtual string Number { get; set; }
>    }
>
> Here is my configuration
>
> FluentConfiguration fs = Fluently.Configure()
>                        .Database(MsSqlConfiguration.MsSql2005
>                        .ConnectionString(c => c
>                            .Server("servername")
>                            .Database("dbname")
>                            .Username("us")
>                            .Password("pw")))
>                        .Mappings(m =>
>                            m.AutoMappings.Add(
>                            AutoPersistenceModel
>                            .MapEntitiesFromAssemblyOf<Asset>()
>                            .Where(t => t.Namespace ==
> "AssetTracking.Core.Entities")));
>
>
> I then do the insertion:
>
>            UnitOfWork.UnitOfWork.Start();
>
>            Repository<Vehicle> vehicles = new Repository<Vehicle>();
>
>            var veh1Asset = new Asset
>            {
>                AssetType = assetType,
>                Name = "Asset 1",
>                Number = "123",
>
>            };
>
>            //Repository<Asset> assets = new Repository<Asset>();
>            //assets.Add(veh1Asset);
>
>            //List<Asset> assList = new List<Asset>();
>            //assList.Add(veh1Asset);
>
>            // add 2 vehicles
>            var veh1 = new Vehicle
>            {
>                Description = "Truck 101, this is a long standing blah
> blah blah",
>                Name = "Truck 101",
>                Image = veh1Image,
>                DrawingImage = vehImage2,
>
>            };
>
>            veh1.AddAsset(veh1Asset);
>
>            vehicles.Add(veh1);
>        }
>
> Now I've tried adding it different ways before and after and in any
> case I try, the Vehicle_Id is always null in the DB.
>
> Am I missing something?
>
> Sorry if I've missed something simple!!
>
> Cheers, Sarkie.
>
> >
>


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