Thank you very much for your patient and your answer.
I do not know If i have understud properly the concept of this: " Both sides of the now one to many need to be saved or updated first. " For instance, I have created a 2 new tables to do the tests. Teachers and Classes. They have only the attitubutes Id and Name. And I have added a relation one to many from teacher to classes. public class Classes : I_DTO { public virtual int Id { get; set; } public virtual string Name { get; set; } public Classes() { } } namespace ExCon_DAO_SQL.DTO.Wall { public class Teacher : I_DTO { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Classes> Classes { get; set; } public Teacher() { Classes = new List<Classes>(); } } public class Teacher_Map : IAutoMappingOverride<Teacher> { public void Override(AutoMapping<Teacher> mapping) { mapping.HasMany(x => x.Classes).LazyLoad(). Inverse().AsBag().ForeignKeyConstraintName("Teacher_Id").Cascade.AllDeleteOrphan(); } } *Ok, I have Saved a Teacher with a clases in the list of clases. All elements are saved in the database but the clases elements have in the database the attribute Teacher_Id as null. So the relation is not saved. Is possible to use an unidirectional relationship one to many and get the foreing key saved???????* is this behaivor normal? second test: public class Classes : I_DTO { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual Teacher teacher { get; set; } public Classes() { teacher = new Teacher(); } } public class Classes_Map : IAutoMappingOverride<Classes> { public void Override(AutoMapping<Classes> mapping) { mapping.References(x => x.teacher).Column("Teacher_Id"); } } Now I have been able to get the target but in this way: Teacher profe = new Teacher(); profe.Name = "Peter"; List<Classes> classes = new List<Classes>(); Classes clase1 = new Classes(); clase1.Name = "Class1"; clase1.teacher = profe; classes.Add(clase1); profe.Classes = classes; DAO_Result resultado = SQL_DAO_Service.Add<Teacher>(profe); I this bidirectional example, I have to add to the teacher the clasess, and each class have to has as well the reference of the teacher to se that in the save it is able to generate all properly is this behaviour correct? And last but not least If I have do and update of this teacher and and 2 clases with him, and after that I remove one of the element of the classes list, and I update the teacher, the system is not able to know that What I want is to delete the class from the database, so i will have to check on my own if the list of clases does not have and ald element to delete it... is this correct? thanks a lot!!! best regards... El miércoles, 24 de agosto de 2016, 14:21:20 (UTC+2), Ivan Ruiz de Eguilaz Sosoaga escribió: > > I have problems generating a new table by using HasManyToMany only When I > have a IDictonary as a source, for instance If I try it with an IList I do > not have any problem and I see how a new table is generated and the > relations. But I need to use a IDictioonary > > The example: > > > public class Email: I_CLASS > { > > public virtual int Id { get; set; } > public virtual IDictionary<Person, short> Destiny_Persons { get; set; } > > } > > public class Person: I_CLASS > { > > public virtual int Id { get; set; } > > > } > > class Notification_DTO_Map : IAutoMappingOverride<Notification_DTO> > { > public void Override(AutoMapping<Notification_DTO> mapping) > { > > mapping.HasManyToMany<User_DTO>(x => > x.Destiny_Users).Table("Destiny_Persons") > .ParentKeyColumn("Email") > .ChildKeyColumn("Person") > .AsEntityMap().Element("Email_Status", part => > part.Type<short>()); > } > > } > > my target is to have that dictionary and a new table called > Destiny_Persons with the followinf attributtes: > > - Person_Id (int) PK FK > - Email_Id (int) PK FK > - Status (short) not null > > The status won´t be part of the PK > > If a use a IList like this public virtual IList<Person> Destiny_Persons { > get; set; } > and in the mapping: mapping.HasManyToMany(x => > x.Destiny_Persons ).Table("Destiny_Persons"); > this works without the Status attributte > > I have tried a lot of different ways of putting this such as changing the > order of the elements in the dictionary <short, Person>, using asMap > instead of AsEntityMap, not using partenkeycolums and child, changing the > order... and so on > > I do not have any error when I generate the database but I am not able to > generate the table Destiny_Persons when I have a IDictionary as a source > > Thanks > > > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To unsubscribe from this group and stop receiving emails from it, send an email to fluent-nhibernate+unsubscr...@googlegroups.com. To post to this group, send email to fluent-nhibernate@googlegroups.com. Visit this group at https://groups.google.com/group/fluent-nhibernate. For more options, visit https://groups.google.com/d/optout.