Guest User

Untitled

a guest
Jun 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public class Document
  2. {
  3. public virtual int Id { get; set; }
  4. public virtual IList<File> Files { get; set; }
  5. }
  6. public class File
  7. {
  8. public virtual int Id { get; protected set; }
  9. public virtual Document Document { get; set; }
  10. }
  11.  
  12. public class HasManyConvention : IHasManyConvention
  13. {
  14. public bool Accept(IOneToManyPart target)
  15. {
  16. return true;
  17. }
  18. public void Apply(IOneToManyPart target)
  19. {
  20. target.Cascade.All();
  21. }
  22. }
  23.  
  24. public class DocumentMappingOverride : IAutoMappingOverride<Document>
  25. {
  26. public void Override(AutoMap<Document> mapping)
  27. {
  28. mapping.HasMany(x => x.Files)
  29. .Inverse()
  30. // this line has no effect
  31. .Cascade.AllDeleteOrphan();
  32. }
  33. }
  34.  
  35. public class FileMappingOverride : IAutoMappingOverride<File>
  36. {
  37. public void Override(AutoMap<File> mapping)
  38. {
  39. mapping.References(x => x.Document).Not.Nullable();
  40. }
  41. }
  42.  
  43. public class DocumentConvention : IClassConvention
  44. {
  45. public bool Accept(IClassMap target)
  46. {
  47. return target.EntityType == typeof(Document);
  48. }
  49. public void Apply(IClassMap target)
  50. {
  51. target.SetAttribute("cascade", "all-delete-orphan");
  52. }
  53. }
  54.  
  55. public class DocumentConvention : IClassConvention
  56. {
  57. public bool Accept(IClassMap target)
  58. {
  59. return target.EntityType == typeof(Document);
  60. }
  61. public void Apply(IClassMap target)
  62. {
  63. target.HasMany<Document, File>(x => x.Files)
  64. .Inverse()
  65. .Cascade.AllDeleteOrphan();
  66. }
  67. }
  68.  
  69. "Duplicate collection role mapping Document.Files"
  70.  
  71. mapping.IgnoreProperty(x => x.Files);
  72.  
  73. return target.EntityType == typeof(Document);
Add Comment
Please, Sign In to add comment