0

So, I am using Entity Framework Code First. This is the model:

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; }
}

I need to refer the fields (OriginLocalId, DestinationLocalId) in StockMoveTransfer to be the same for the StockMoveIn and StockMoveOut, but Entity Framework expect to new fields.

The SQL DDL generated is:

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])
);

Well, how can I configure the Entity Framework to point for the existing fields?

iuristona
  • 927
  • 13
  • 30

0 Answers0