リバース エンジニアリング Code First によって行われたいくつかの選択の背後にある理由をよりよく理解しようとしています。
これはスキーマです。ユーザーとアフィリエイトの両方に FK があることを示しています。
CREATE TABLE [dbo].[Orders] (
[ID] INT IDENTITY (1, 1) NOT NULL,
[idUser] INT NOT NULL,
[orderDate] SMALLDATETIME NOT NULL,
[total] MONEY NOT NULL,
[idAffiliate] INT NOT NULL,
CONSTRAINT [PK_cartHead] PRIMARY KEY CLUSTERED ([ID] ASC) WITH (FILLFACTOR = 90),
CONSTRAINT [FK_Orders_Affiliates] FOREIGN KEY ([idAffiliate]) REFERENCES [dbo].[Affiliates] ([ID]),
CONSTRAINT [FK_Orders_Users] FOREIGN KEY ([idUser]) REFERENCES [dbo].[Users] ([ID])
);
REの世代は次のとおりです。
...
public int ID { get; set; }
public int idUser { get; set; }
public System.DateTime orderDate { get; set; }
public decimal total { get; set; }
public int idAffiliate { get; set; }
public virtual Affiliate Affiliate { get; set; }
public virtual User User { get; set; }
public virtual ICollection<OrdersRow> OrdersRows { get; set; }
OrderMap.cs
// Table & Column Mappings
this.ToTable("Orders");
this.Property(t => t.ID).HasColumnName("ID");
this.Property(t => t.idUser).HasColumnName("idUser");
this.Property(t => t.orderDate).HasColumnName("orderDate");
this.Property(t => t.total).HasColumnName("total");
this.Property(t => t.initiatedBy).HasColumnName("initiatedBy");
this.Property(t => t.idAffiliate).HasColumnName("idAffiliate");
// Relationships
this.HasRequired(t => t.Affiliate)
.WithMany(t => t.Orders)
.HasForeignKey(d => d.idAffiliate);
this.HasRequired(t => t.User)
.WithMany(t => t.Orders)
.HasForeignKey(d => d.idUser);
私が興味を持っているのは、重複のように見えるものです - idAffiliate は機能的に複合オブジェクト - Affiliate と同じです。idUser -> User も同様です。
クラスが両方を望む理由はありますか?
どうも