¿Es posible mapear una relación de uno a uno usando la clave principal y un valor discriminador? Sé que al código primero no le gusta la propiedad del discriminador en la clase concreta y hacer referencia a ella solo en el método Map.Cómo correlacionar el discriminador de herencia como clave compuesta en Entity Framework?
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));
/* esto es lo que actualmente se genera */
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)
)
/* es posible generar/MAP esto y mantener la herencia? */
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)
)
Gracias.
Ese es un punto muy bueno Ladislav y ciertamente responde la pregunta por mí. EF ciertamente desafió mis hábitos de diseño de base de datos. Para mejor, creo. –
Podrían haber permitido readonly aunque .... – VdesmedT