【发布时间】:2014-04-04 20:10:18
【问题描述】:
我在现有数据库中使用 Code First,并且有一个必须映射到两个表的实体,我该如何完成?
数据库:
CREATE TABLE Supplier(
SupplierId bigint identity(1,1) NOT NULL,
SupplierName varchar(60) NOT NULL
)
CREATE TABLE Customer(
CustomerId bigint identity(1,1) NOT NULL,
CustomerName varchar(60) NOT NULL
)
CREATE TABLE SupplierPayments(
SupplierPaymentNumber bigint NOT NULL,
SupplierId bigint NOT NULL,
PaymentValue decimal(19,4) NOT NULL
)
CREATE TABLE CustomerPayments(
CustomerPaymentNumber bigint NOT NULL,
CustomerId bigint NOT NULL,
PaymentValue decimal(19,4) NOT NULL
)
ALTER TABLE SupplierPayments
ADD CONSTRAINT PK_SupplierPayments
PRIMARY KEY CLUSTERED (SupplierPaymentNumber, SupplierId ASC);
ALTER TABLE CustomerPayments
ADD CONSTRAINT PK_CustomerPaymentss
PRIMARY KEY CLUSTERED (CustomerPaymentNumber, CustomerId ASC);
还有我的实体:
public partial class Supplier{
public long SupplierId{ get; set; }
public string Name{ get; set; }
public virtual List<Payment> Payments{ get; set; }
}
public partial class Customer{
public long CustomerId{ get; set; }
public string Name{ get; set; }
public virtual List<Payment> Payments{ get; set; }
}
public partial class Payment{
public long PaymentNumber{ get; set; }
public decimal Value{ get; set; }
}
如何配置(使用 Fluent API)供应商和客户到付款之间的多对一关系?
【问题讨论】:
标签: c# entity-framework