0

そのため、Entity Framework Code First を使用しています。これはモデルです:

public class StockMove
{
    public int Id { get; set; }

    public int ProductId { get; set; }
    public virtual Product Product { get; set; }
}

public class StockMoveOut : StockMove
{
    public int CustomerId { get; set; }
    public virtual Customer Customer { get; set; }

    public int OriginLocalId { get; set; }
    public virtual Local OriginLocal { get; set; }
}

public class StockMoveIn : StockMove
{
    public int SupplierId { get; set; }
    public virtual Supplier Supplier { get; set; }

    public int DestinationLocalId { get; set; }
    public virtual Local DestinationLocal { get; set; }
}

public class StockMoveTransfer : StockMove
{
    public int OriginLocalId { get; set; } //should be the same for StockMoveOut
    public virtual Local OriginLocal { get; set; }

    public int DestinationLocalId { get; set; } //should be the same for StockMoveIn
    public virtual Local DestinationLocal { get; set; }
}

public class DataContext : DbContext
{
    public DbSet<StockMove> StockMoves { get; set; }
}

StockMoveTransfer のフィールド (OriginLocalId、DestinationLocalId) が StockMoveIn と StockMoveOut で同じになるように参照する必要がありますが、Entity Framework は新しいフィールドを想定しています。

生成される SQL DDL は次のとおりです。

create table [dbo].[StockMoves] (
    [Id] [int] not null identity,
    [ProductId] [int] not null,
    [CustomerId] [int] null,
    [OriginLocalId] [int] null,
    [SupplierId] [int] null,
    [DestinationLocalId] [int] null,
    [OriginLocalId1] [int] null, -- should not exists
    [DestinationLocalId1] [int] null, -- should not exists
    [Discriminator] [nvarchar](128) not null,
    primary key ([Id])
);

では、既存のフィールドを指すように Entity Framework を構成するにはどうすればよいでしょうか?

4

0 に答える 0