Guest User

Untitled

a guest
Sep 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Auditing many-to-many relationships in Entity Framework?
  2. public class Rfi
  3. {
  4. public Guid Id {get;set;}
  5. public string Number {get;set;}
  6. public virtual ICollection<Attachment> Attachments {get;set;}
  7. }
  8.  
  9. public Class Attachment
  10. {
  11. public Guid Id {get;set;}
  12. public string Name {get;set;}
  13. public string Description {get;set;}
  14. public string FileName {get;set;}
  15. public string Path {get;set;}
  16. }
  17.  
  18. public class RfiMapping: EntityTypeConfiguration<Rfi>
  19. {
  20. public Rfimapping()
  21. {
  22. HasMany(r => r.Attachments).WithMany().Map(m =>
  23. {
  24. m.MapLeftKey("RfiId");
  25. m.MapRightKey("AttachmentId");
  26. m.ToTable("Rfi_Attachments");
  27. });
  28. }
  29. }
  30.  
  31. public void AddAttachmentToRfi(Attachment attachment, Guid rfiId)
  32. {
  33. var rfi = _rfiRepository.FindById(rfiId);
  34. rfi.Attachments.Add(attachment);
  35. _rfiRepository.UnitOfWork.Commit();
  36. }
Add Comment
Please, Sign In to add comment