Any ideas james,

I have tested deleting updating and selecting, and this works.

I just cant insert a record - as it tries to update.



On Mar 8, 12:48 pm, James Gregory <jagregory....@gmail.com> wrote:
> I'm not really familiar with composite keys in a production environment
> (nothing outside of writing the code to support it in FNH), could you give
> me an example of the actual code you're using to save your entities? Even
> more helpful would be if you could reduce your mappings down to the bare
> minimum needed to reproduce the problem.
>
>
>
> On Sun, Mar 8, 2009 at 12:07 AM, sianabanana <sianm...@hotmail.com> wrote:
>
> > Any ideas? I could really do with some help on this one.
> > Much appriciated :)
>
> > On Mar 6, 11:40 pm, sianabanana <sianm...@hotmail.com> wrote:
> > > I have a more complex many to many relationship and need to create the
> > > link between the manys as an object to store further data.
>
> > > Order  - id, date
>
> > > Order Product -  orderid, productid, quantity
>
> > > Product - id, name
>
> > > I am using auto mapping, and i am overriding the mapping to specify
> > > anything that doesnt fall in to the convention.
>
> > > No matter what conbination of properties i use, i cannot get the order
> > > product object to persis to the database.
>
> > > When profiling, the order object causes an insert, the product causes
> > > an insert
> > > but the order product causes an update - but there is nothing to
> > > update and this throws the following error. Unexpected row count: 0;
> > > expected: 1 - as you would expect.
>
> > > I would love if someone could show me a working example of how to get
> > > this working.
>
> > > 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();
> > >         }
> > >     }
>
> > >         public class OrderMapOverride : IAutoMappingOverride<Order>
> > >     {
> > >         public void Override(AutoMap<Order> map)
> > >         {
> > >             map.HasMany(x => x.Products)
> > >                 .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)
> > >             //    .WithForeignKey("Id").TheColumnNameIs("OrderId");
> > >             //map.References(x => x.Product)
> > >             //    .WithForeignKey("Id").TheColumnNameIs("ProductId");
> > >         }
> > >     }
>
> > > public class ProductMapOverride : IAutoMappingOverride<Product>
> > >     {
> > >         public void Override(AutoMap<Product> map)
> > >         {
> > >             map.HasMany(x => x.Orders)
> > >                 .Inverse();
> > >         }
> > >     }
>
> > > ps. i set the following in my conventions.
> > > 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();
>
> > > I have puzzled over this for days and really could do with some help
> > > on this one.
>
> > > Thanks- 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