Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Auditing many-to-many relationships in Entity Framework?
- public class Rfi
- {
- public Guid Id {get;set;}
- public string Number {get;set;}
- public virtual ICollection<Attachment> Attachments {get;set;}
- }
- public Class Attachment
- {
- public Guid Id {get;set;}
- public string Name {get;set;}
- public string Description {get;set;}
- public string FileName {get;set;}
- public string Path {get;set;}
- }
- public class RfiMapping: EntityTypeConfiguration<Rfi>
- {
- public Rfimapping()
- {
- HasMany(r => r.Attachments).WithMany().Map(m =>
- {
- m.MapLeftKey("RfiId");
- m.MapRightKey("AttachmentId");
- m.ToTable("Rfi_Attachments");
- });
- }
- }
- public void AddAttachmentToRfi(Attachment attachment, Guid rfiId)
- {
- var rfi = _rfiRepository.FindById(rfiId);
- rfi.Attachments.Add(attachment);
- _rfiRepository.UnitOfWork.Commit();
- }
Add Comment
Please, Sign In to add comment