How to map inheritance discriminator as composite key in Entity Framework?
entity-framework
Solution
As I know it is not possible because EF doesn't allow using discriminator column in any other mapping. Also your target mapping will demand that your transaction class also has `FlightTypeId` property (class must have properties for the whole key) but it would break the meaning of the inheritance because you would be able to change the value of that property and make your inheritance inconsistent.
Problem
Is it possible to map a one to one relationship using the parent key and a discriminator value? I know that code first does not like the discriminator property on the concrete class and to reference it only in the Map method. ``` 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)); ``` /* this is what is currently generated */ ``` 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 ) ) ``` /* is it possible to generate/map this and keep inheritance? */ ``` 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 ) ) ``` Thanks.