我试图更好地理解通过逆向工程师代码优先做出的一些选择背后的原因。
这是架构 - 显示我对用户和附属公司都有 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 -> 用户也是如此。
班级是否有理由同时想要两者?
谢谢