inutan
inutan

Reputation: 10888

Fluent Nhibernate - One to Many Mapping Issue

I am getting NHibernate.MappingException while trying to do one-to-many mapping in fluent nhibernate. Below are the snippets from my entity and their mapping classes:

public class ReportRequest : IReportRequestToBeFullyLoaded
{
    public virtual Int32? Id { get; set; }
    public virtual string Description { get; set; }
    public virtual ISet<ReportOutputEmail> ReportOutputEmails { get; set; }
}

public class ReportOutputEmail
{
    public virtual string RecipientAddress { get; set; }
    public virtual string Message { get; set; }
    public virtual ReportRequest ReportRequest { get; set; }
}

public class ReportRequestMap : ClassMap<ReportRequest>
{
    public ReportRequestMap()
    {
        Table("ReportRequest");
        Id(x => x.Id).UnsavedValue(null).GeneratedBy.Native();
        Map(x => x.Description);
        HasMany(x => x.ReportOutputEmails).Table("ReportOutputEmail")
            .ForeignKeyConstraintName("FK_ReportOutputEmail_ReportRequest")
            .KeyColumn("ReportRequestId")
            .AsSet()
            .Inverse()
            .Cascade.AllDeleteOrphan();
    }
}

public class ReportOutputEmailMap: ClassMap<ReportOutputEmail>
{
    public ReportOutputEmailMap()
    {
        References(x => x.ReportRequest)
            .ForeignKey("FK_ReportOutputEmail_ReportRequest")
            .Column("ReportRequestId");
        Map(x => x.RecipientAddress);
        Map(x => x.Message);
    }
}

There is some issue with one-to-many mapping between ReportRequest->ReportOutputEmail,
Getting error:

Error: NHibernate.MappingException: (XmlDocument)(3,6): XML validation error: The  
element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element  
'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements  expected:  'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in     namespace  'urn:nhibernate-mapping-2.2'.

Can anyone help figuring out.

Thank you!

Upvotes: 1

Views: 821

Answers (1)

James Gregory
James Gregory

Reputation: 14223

Your ReportOutputEmail doesn't have an identity, it'll need one if its going to be an entity.

Also, I recommend you upgrade your copy of Fluent NHibernate, as this is reported in a much more helpful manner since 1.1 (you'd get an identity missing message).

Upvotes: 2

Related Questions