I have a structure where I have a ManyToManyToMany relationship.

This is my (truncated) fluent mappings.

    public AgencyMap()
    {
        Id(x => x.AgencyId, "AgencyId");                        
        Map(x => x.AgencyCode, "AgencyCode");
        HasManyToMany<Personnel>(x => x.Personnel)
            .WithTableName("AgencyPersonnel")
            .WithParentKeyColumn("AgencyId")
            .WithChildKeyColumn("PersonnelId").Cascade.All().LazyLoad();
    }

    public PersonnelMap()
    {
        Id(x => x.PersonnelId, "PersonnelId");
        HasManyToMany<Discipline>(x => x.Disciplines)
            .WithTableName("AgencyPersonnelDiscipline")
            .WithParentKeyColumn("AgencyPersonnelId")
            .WithChildKeyColumn("DisciplineId")
            .Cascade.SaveUpdate().LazyLoad();
    }                   

    public DisciplineMap()
    {
        SchemaIs("dbo");                        
        Id(x => x.DisciplineId, "DisciplineId");                        
        Map(x => x.DisciplineCode, "DisciplineCode");                   
        Map(x => x.Description, "Description");                 
    }   

If I then run code like this.

    Agency agency = m_AgencyRepository.Get(10);
    var personnel = new Personnel() { ... };
    personnel.Disciplines.Add(new Discipline() { ... });
    agency.Personnel.Add(personnel);
    m_AgencyRepository.Save(agency);

When I run this code I get this error.

    could not insert collection:
[PPSS.Model.Personnel.Disciplines#22][SQL: SQL not available]
    The INSERT statement conflicted with the FOREIGN KEY constraint
"AgencyPersonnel_AgencyPersonnelDiscipline_FK1". The conflict occurred
in database "PPSS2", table "dbo.AgencyPersonnel", column
'AgencyPersonnelId'.\r\nThe statement has been terminated.

If I add an inverse to the ManyToMany in personnel then the Personnel
is saved but not the disciplines (no exception is raised).

How should this mapping be done?


Craig.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to