Có thể lập bản đồ mối quan hệ một đến một bằng cách sử dụng khóa cha và giá trị phân biệt đối xử không? Tôi biết rằng mã đầu tiên không thích thuộc tính phân biệt đối xử trên lớp bê tông và chỉ tham chiếu nó trong phương thức Map.Làm thế nào để ánh xạ phân biệt đối xử thừa kế dưới dạng khóa tổng hợp trong khung Entity?
FlightTypes { Inbound = 1, Outbound = 2}
public class Transaction
- int TransactionId
- int? InboundFlightId
- InboundTransactionFlight InboundFlight
- int? OutboundFlightId
- OutboundTransactionFlight OutboundFlight
public abstract class TransactionFlight
- TransactionFlightId
public class InboundTransactionFlight : Flight
- List<Transaction> InboundFor
public class OutboundTransactionFlight : Flight
- List<Transaction> OutboundFor
Entity<InboundTransactionFlight>().Map(m => m.Requires("FlightTypeId").HasValue(1));
Entity<OutboundTransactionFlight>().Map(m => m.Requires("FlightTypeId").HasValue(2));
/* này là những gì hiện đang tạo ra */
CREATE TABLE Transactions (
TransactionId int NOT NULL,
InboundFlightId int NULL,
OutboundFlightId int NULL
)
CREATE TABLE TransactionFlights (
TransactionFlightId int NOT NULL,
FlightTypeId int NOT NULL,
...
CONSTRAINT PK_TransactionFlights PRIMARY KEY CLUSTERED (TransactionFlightId)
)
/* là nó có thể tạo/bản đồ này và giữ quyền thừa kế? */
CREATE TABLE Transactions (
TransactionId int NOT NULL,
)
CREATE TABLE TransactionFlights (
TransactionId int NOT NULL,
FlightTypeId int NOT NULL,
...
CONSTRAINT PK_TransactionFlights PRIMARY KEY CLUSTERED (TransactionId, FlightTypeId)
)
Cảm ơn.
Đó là một điểm rất tốt Ladislav và chắc chắn trả lời câu hỏi cho tôi. EF chắc chắn đã thách thức thói quen thiết kế cơ sở dữ liệu của tôi. Tôi tin là tốt hơn. –
Họ có thể đã cho phép chỉ đọc mặc dù .... – VdesmedT