Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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; }
- }
- public class HasManyConvention : IHasManyConvention
- {
- public bool Accept(IOneToManyPart target)
- {
- return true;
- }
- public void Apply(IOneToManyPart target)
- {
- target.Cascade.All();
- }
- }
- public class DocumentMappingOverride : IAutoMappingOverride<Document>
- {
- public void Override(AutoMap<Document> mapping)
- {
- mapping.HasMany(x => x.Files)
- .Inverse()
- // this line has no effect
- .Cascade.AllDeleteOrphan();
- }
- }
- public class FileMappingOverride : IAutoMappingOverride<File>
- {
- public void Override(AutoMap<File> mapping)
- {
- mapping.References(x => x.Document).Not.Nullable();
- }
- }
- 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");
- }
- }
- 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();
- }
- }
- "Duplicate collection role mapping Document.Files"
- mapping.IgnoreProperty(x => x.Files);
- return target.EntityType == typeof(Document);
Add Comment
Please, Sign In to add comment