Hello,

Im having problems using the many to many features in NHBibernate. My 
problem is that I cant add an item to an already created object. The only 
way for it to work I have to create everything new in the same ISession. Am 
I doing it wrong or is this how it works?

my application is developed under Asp.NET MVC 4 with autofac. I'm using the 
repository and unit of work pattern.

My objects are the following:

*

    [DataContract(IsReference = true)]

    [KnownType(typeof(Provincia))]

    [KnownType(typeof(CodigoPostal))]

    public partial class Localidad

    {

        [DataMember]

        public virtual int Id  { get; set; }


        [DataMember]

        public virtual string Nombre  { get; set; }


        [DataMember]

        public virtual Provincia Provincia  { get; set; }

        

        [DataMember]

        public virtual IList<CodigoPostal> CodigoPostal { get; set; }

    }

    [DataContract(IsReference = true)]

    [KnownType(typeof(Localidad))]

    public partial class CodigoPostal

    {

        [DataMember]

        public virtual int Id { get; set; }


        [DataMember]

        public virtual string Codigo { get; set; }


        [DataMember]

        public virtual IList<Localidad> Localidad  { get; set; }

    }


My mappings:


    public partial class CodigoPostalMap : ClassMap<CodigoPostal>

    {

        public CodigoPostalMap()

        {

            Id(x => x.Id).GeneratedBy.Identity();

            Map(x => x.Codigo).Length(5).Not.Nullable();

            HasManyToMany(x => 
x.Localidad).Inverse().LazyLoad().Cascade.SaveUpdate();

        }

    }


    public partial class LocalidadMap : ClassMap<Localidad>

    {

        public LocalidadMap()

        {

            Id(x => x.Id).GeneratedBy.Identity();

            Map(x => x.Nombre).Length(100).Not.Nullable();

            References(x => x.Provincia).Not.Nullable();

            HasManyToMany(x => 
x.CodigoPostal).LazyLoad().Cascade.SaveUpdate();

        }

    }


*

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/dLVeVjIHsj8J.
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/nhusers?hl=en.

Reply via email to