Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DataContract]
- public class Invoice : EntityBase, IIdentifiableEntity
- {
- [DataMember]
- public int InvoiceId { get; set; }
- [DataMember]
- public int OrderId { get; set; }
- public Order Order { get; set; }
- public ICollection<Payment> Payments { get; set; }
- public int EntityId
- {
- get { return InvoiceId; }
- set { InvoiceId = value; }
- }
- }
- [DataContract]
- public class Payment : EntityBase, IIdentifiableEntity
- {
- [DataMember]
- public int PaymentId { get; set; }
- public ICollection<Invoice> Invoices { get; set; }
- public int EntityId
- {
- get { return PaymentId; }
- set { PaymentId = value; }
- }
- }
- [DataContract]
- public class InvoicePayment
- {
- [DataMember]
- public int PaymentId { get; set; }
- [DataMember]
- public int InvoiceId { get; set; }
- public Payment Payment { get; set; }
- public Invoice Invoice { get; set; }
- }
- //In the model builder
- modelBuilder.Entity<InvoicePayment>().HasKey(k => new
- {
- k.InvoiceId,
- k.PaymentId
- });
- modelBuilder.Entity<InvoicePayment>()
- .HasRequired(p => p.Payment)
- .WithMany()
- .HasForeignKey(p => p.PaymentId);
- modelBuilder.Entity<InvoicePayment>()
- .HasRequired(p => p.Invoice)
- .WithMany()
- .HasForeignKey(p => p.InvoiceId);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement