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.

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