I have two classes

public class Document
{
    public virtual int Id { get; set; }
    public virtual IList<File> Files { get; set; }
}
public class File
{
    public virtual int Id { get; protected set; }
    public virtual Document Document { get; set; }
}

with the following convention:

public class HasManyConvention : IHasManyConvention
{
    public bool Accept(IOneToManyPart target)
    {
        return true;
    }

    public void Apply(IOneToManyPart target)
    {
        target.Cascade.All();
    }
}

and these mapping overrides

public class DocumentMappingOverride : IAutoMappingOverride<Document>
{
    public void Override(AutoMap<Document> mapping)
    {
        mapping.HasMany(x => x.Files)
            .Inverse()
            .Cascade.AllDeleteOrphan();
    }
}
public class FileMappingOverride : IAutoMappingOverride<File>
{
    public void Override(AutoMap<File> mapping)
    {
        mapping.References(x => x.Document).Not.Nullable();
    }
}


I understand that I need to make an IClassConvention for Document to
change the cascade behaviour, however I can't get this to work!

If i do this:

public class DocumentConvention : IClassConvention
{
    public bool Accept(IClassMap target)
    {
        return target.EntityType == typeof(Document);
    }

    public void Apply(IClassMap target)
    {
        target.SetAttribute("cascade", "all-delete-orphan");
    }
}

I get: "The 'cascade' attribute is not declared."

If i do this:

public class DocumentConvention : IClassConvention
{
    public bool Accept(IClassMap target)
    {
        return target.EntityType == typeof(Document);
    }

    public void Apply(IClassMap target)
    {
        target.HasMany<Document, File>(x => x.Files)
            .Inverse()
            .Cascade.AllDeleteOrphan();
    }
}

Then I get: "Duplicate collection role mapping
Redcliffe.Domain.Entities.Document.Files"

so i added:

mapping.IgnoreProperty(x => x.Files);

to my document mapping, but then Files is always empty.

What am I doing wrong?

How can I override the cascade rule for a single HasMany relationship?

Thanks

Andrew


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

Reply via email to