2
我對現有數據庫使用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; }
}
如何配置(用流利的API),以支付供應商和客戶之間的多到一的關係?
沒有人可以幫助我嗎? –