Just replied to another thread about this. We don't support complex
composite-ids (one's that are essentially components) right now. I would
wholeheartedly recommend that you don't use composite-ids if at all
possible, use surrogate keys.

On Fri, Mar 13, 2009 at 9:56 PM, sianabanana <sianm...@hotmail.com> wrote:

>
> Looking in to this some more, i dont think what im trying to acheive
> can be done.
>
> I found this issue in the log which seems to describe the problem im
> having.
> http://code.google.com/p/fluent-nhibernate/issues/detail?id=27
>
> I think if i tried to make a composite id that was of simple types
>
> like
> OrderID and ProductId it might work.
> But i think the problem is that it cannot cope with the complex types
> that im trying to implement.
> Order and Product.
>
> Anyone else have any ideas about this?
>
> On Mar 11, 3:50 pm, sianabanana <sianm...@hotmail.com> wrote:
> > I think thats where i was about to look next.
> >
> > I will do this and then update.
> >
> > Thanks again for the support so far,
> >
> > On Mar 11, 3:48 pm, James Gregory <jagregory....@gmail.com> wrote:
> >
> >
> >
> > > Well, if you're not able to write tests, then another way would be to
> get
> > > the behavior you desire to work in standard NHibernate using the xml
> > > mappings. If you can succeed at that, then we can compare the mappings
> > > you're using with that to what FNH is generating....
> >
> > > read more »
> >
> > > On Wed, Mar 11, 2009 at 3:42 PM, sianabanana <sianm...@hotmail.com>
> wrote:
> >
> > > > If i swap the WithKeyRefrence to WithKeyProperty i get a mapping
> error
> > > > on start up.
> >
> > > > It then cannot map the OrderProduct
> >
> > > > I wouldnt know where to start making some test cases for this?  I
> dont
> > > > know what you would expect to receive from me?
> >
> > > > On Mar 11, 3:37 pm, James Gregory <jagregory....@gmail.com> wrote:
> > > > > Neither of us said we don't likecomposite-ids, although that may be
> the
> > > > > case, we just don't have a great deal of experience using them.
> This is
> > > > why
> > > > > we're not being all that helpful, because we don't fully understand
> them
> > > > > ourselves. You have to appreciate that for FNH to support a
> feature, all
> > > > we
> > > > > have to do is output the xml that NHibernate expects, not to
> actually
> > > > > understand what NH does with it.
> > > > > What would be more useful than a console app would be a test, or
> set of
> > > > > tests, that we could add to the FNH codebase to ensure that if
> there is a
> > > > > bug it never regresses. A console app will require one of us to
> derive
> > > > tests
> > > > > from it, which takes more work....
> >
> > > > > read more »
> >
> > > > > It may be my naïvety showing, but I believe you should be using
> > > > > WithKeyProperty rather than WithKeyReference. I could be wrong
> though.
> >
> > > > > On Wed, Mar 11, 2009 at 3:14 PM, sianabanana <sianm...@hotmail.com
> >
> > > > wrote:
> >
> > > > > > No more responses?
> >
> > > > > > Any one can shed any light.
> >
> > > > > > Here is the code from the example console application if anyone
> wants
> > > > > > to have a go?
> >
> > > > > > using System;
> > > > > > using System.Collections.Generic;
> > > > > > using System.Linq;
> > > > > > using System.Text;
> > > > > > using FluentNHibernate;
> > > > > > using Domain;
> > > > > > using FluentNHibernate.AutoMap;
> > > > > > using FluentNHibernate.Cfg.Db;
> > > > > > using FluentNHibernate.AutoMap.Alterations;
> > > > > > using Overrides;
> > > > > > using NHibernate;
> >
> > > > > > namespace CompositeKeyExample
> > > > > > {
> > > > > >    class Program
> > > > > >    {
> > > > > >        public static ISession Session { get; set; }
> >
> > > > > >        public static ITransaction Transaction { get; set; }
> >
> > > > > >        static void Main(string[] args)
> > > > > >        {
> > > > > >            Session = SessionFactory.CreateSession();
> > > > > >            Transaction = Session.BeginTransaction();
> >
> > > > > >            Order o = new Order();
> > > > > >            o.OrderDate = DateTime.Now;
> >
> > > > > >             Product p = new Product();
> > > > > >            p.Name = "Custom Item";
> >
> > > > > >             OrderProduct op = new OrderProduct();
> > > > > >            op.Product = p;
> > > > > >            op.Order = o;
> > > > > >            op.Quantity = 1;
> >
> > > > > >             o.Products = new List<OrderProduct>();
> > > > > >            o.Products.Add(op);
> >
> > > > > >             Session.SaveOrUpdate(o);
> >
> > > > > >            //Order o = new Order();
> > > > > >             //o.OrderDate = DateTime.Now;
> > > > > >            //Session.SaveOrUpdate(o);
> >
> > > > > >            //Product p = new Product();
> > > > > >            //p.Name = "Custom Item";
> > > > > >            //Session.SaveOrUpdate(p);
> >
> > > > > >            //OrderProduct op = new OrderProduct();
> > > > > >            //op.Product = p;
> > > > > >            //op.Order = o;
> > > > > >            //op.Quantity = 1;
> > > > > >            //Session.SaveOrUpdate(op);
> >
> > > > > >            //o.Products = new List<OrderProduct>();
> > > > > >            //o.Products.Add(op);
> >
> > > > > >             try
> > > > > >            {
> > > > > >                Transaction.Commit();
> > > > > >            }
> > > > > >            catch(Exception ex)
> > > > > >            {
> > > > > >                Transaction.Rollback();
> > > > > >                throw ex;
> > > > > >            }
> >
> > > > > >                //Session.Flush();
> > > > > >                Session.Close();
> > > > > >        }
> >
> > > > > >        private static ISessionSource _factory;
> > > > > >        public static ISessionSource SessionFactory
> > > > > >        {
> > > > > >            get
> > > > > >            {
> > > > > >                if (_factory == null)
> > > > > >                {
> >
> > > > > >                    IDictionary<string, string> _properties =
> > > > > > MsSqlConfiguration
> > > > > >                        .MsSql2005
> > > > > >                        .ConnectionString( x =>
> > > > > > x.FromConnectionStringWithKey("MsSqlConnStr"))
> > > > > >                        .ToProperties();
> >
> > > > > >                    FluentNHibernate.AutoMap.AutoPersistenceModel
> > > > > > _mappings = AutoPersistenceModel
> > > > > >                        .MapEntitiesFromAssemblyOf<Order>()
> > > > > >                        .Where(t => t.Namespace == typeof
> > > > > > (Order).Namespace)
> > > > > >
>  .UseOverridesFromAssemblyOf<OrderMapOverride>
> > > > > > ()
> > > > > >                        .WithConvention(convention =>
> > > > > >                         {
> > > > > >                            convention.GetPrimaryKeyNameFromType =
> > > > > > type => type.Name + "Id";
> > > > > >                            convention.GetForeignKeyNameOfParent =
> > > > > > type => type.Name + "Id";
> > > > > >                            convention.GetForeignKeyName = type =>
> > > > > > type.Name + "Id";
> > > > > >                            convention.GetManyToManyTableName =
> > > > > > (parent, child) => parent.Name + "_" + child.Name;
> > > > > >                            convention.OneToManyConvention = o =>
> > > > > > o.Cascade.All();
> > > > > >                            convention.OneToOneConvention = o =>
> > > > > > o.Cascade.All();
> > > > > >                            convention.ManyToOneConvention = o =>
> > > > > > o.Cascade.All();
> > > > > >                         });
> >
> > > > > >                    _factory = new SessionSource(_properties,
> > > > > > _mappings);
> > > > > >                    _factory.BuildSchema();
> > > > > >                }
> >
> > > > > >                return _factory;
> > > > > >            }
> > > > > >        }
> > > > > >    }
> > > > > > }
> > > > > > namespace Domain
> > > > > > {
> > > > > >    public class Order
> > > > > >    {
> > > > > >        public virtual int Id { get; set; }
> >
> > > > > >        public virtual DateTime OrderDate { get; set; }
> >
> > > > > >        public virtual IList<OrderProduct> Products { get; set; }
> > > > > >    }
> >
> > > > > >    public class Product
> > > > > >    {
> > > > > >        public virtual int Id { get; set; }
> > > > > >        public virtual string Name { get; set; }
> >
> > > > > >        public virtual IList<OrderProduct> Orders { get; set; }
> > > > > >    }
> >
> > > > > >    public class OrderProduct
> > > > > >    {
> > > > > >        public virtual Order Order { get; set; }
> > > > > >        public virtual Product Product { get; set; }
> > > > > >        public virtual int Quantity { get; set; }
> >
> > > > > >        public override bool Equals(object obj)
> > > > > >        {
> > > > > >            if (obj == null)
> > > > > >                return false;
> >
> > > > > >            OrderProduct other = (OrderProduct)obj;
> >
> > > > > >            return (Order.Id == other.Order.Id && Product.Id ==
> > > > > > other.Product.Id);
> > > > > >        }
> >
> > > > > >        public override int GetHashCode()
> > > > > >        {
> > > > > >            return string.Format("{0}|{1}",
> > > > > >                Order.Id, Product.Id).GetHashCode();
> > > > > >        }
> > > > > >    }
> > > > > > }
> >
> > > > > > namespace Overrides
> > > > > > {
> > > > > >    public class OrderMapOverride : IAutoMappingOverride<Order>
> > > > > >    {
> > > > > >        public void Override(AutoMap<Order> map)
> > > > > >        {
> > > > > >            map.HasMany(x => x.Products)
> > > > > >                .Inverse();
> > > > > >        }
> > > > > >    }
> >
> > > > > >     public class ProductMapOverride :
> IAutoMappingOverride<Product>
> > > > > >    {
> > > > > >        public void Override(AutoMap<Product> map)
> > > > > >        {
> > > > > >            map.HasMany(x => x.Orders)
> > > > > >                .Inverse();
> > > > > >        }
> > > > > >    }
> >
> > > > > >    public class OrderProductMapOverride :
> > > > > > IAutoMappingOverride<OrderProduct>
> > > > > >    {
> > > > > >        public void Override(AutoMap<OrderProduct> map)
> > > > > >        {
> > > > > >            map.UseCompositeId()
> > > > > >                .WithKeyReference(x => x.Order, "OrderId")
> > > > > >                .WithKeyReference(x => x.Product, "ProductId");
> >
> > > > > >            //map.HasOne(x => x.Order)
> > > > > >            //    .WithForeignKey("OrderId");
> >
> > > > > >            //map.HasOne(x => x.Product)
> > > > > >            //    .WithForeignKey("ProductId");
> >
> > > > > >            //map.References(x => x.Order)
> > > > > >            //
> >
> > ...
> >
> > read more »- Hide quoted text -
> >
> > - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to