Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. [DataContract]
  2. public class Invoice : EntityBase, IIdentifiableEntity
  3. {
  4.     [DataMember]
  5.     public int InvoiceId { get; set; }
  6.     [DataMember]
  7.     public int OrderId { get; set; }
  8.  
  9.     public Order Order { get; set; }
  10.     public ICollection<Payment> Payments { get; set; } 
  11.     public int EntityId
  12.     {
  13.         get { return InvoiceId; }
  14.         set { InvoiceId = value; }
  15.     }
  16. }
  17.  
  18. [DataContract]
  19. public class Payment : EntityBase, IIdentifiableEntity
  20. {
  21.     [DataMember]
  22.     public int PaymentId { get; set; }
  23.  
  24.     public ICollection<Invoice> Invoices { get; set; }
  25.     public int EntityId
  26.     {
  27.         get { return PaymentId; }
  28.         set { PaymentId = value; }
  29.     }
  30. }
  31.  
  32. [DataContract]
  33. public class InvoicePayment
  34. {
  35.     [DataMember]
  36.     public int PaymentId { get; set; }
  37.  
  38.     [DataMember]
  39.     public int InvoiceId { get; set; }
  40.  
  41.     public Payment Payment { get; set; }
  42.     public Invoice Invoice { get; set; }
  43. }
  44.  
  45. //In the model builder
  46. modelBuilder.Entity<InvoicePayment>().HasKey(k => new
  47. {
  48.     k.InvoiceId,
  49.     k.PaymentId
  50. });
  51. modelBuilder.Entity<InvoicePayment>()
  52.     .HasRequired(p => p.Payment)
  53.     .WithMany()
  54.     .HasForeignKey(p => p.PaymentId);
  55.  
  56. modelBuilder.Entity<InvoicePayment>()
  57.     .HasRequired(p => p.Invoice)
  58.     .WithMany()
  59.     .HasForeignKey(p => p.InvoiceId);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement