0

In have a table in SQL Server defined by

    CREATE TABLE [dbo].[ReportDataV2](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [DataTypeName] [nvarchar](max) NULL,
    [IsInplaceReport] [bit] NOT NULL,
    [PredefinedReportTypeName] [nvarchar](max) NULL,
    [Content] [varbinary](max) NULL,
    [DisplayName] [nvarchar](max) NULL,
    [ParametersObjectTypeName] [nvarchar](max) NULL,
 CONSTRAINT [PK_dbo.ReportDataV2] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

which happens to be the Dev Express XAF Report table.

In my data context I have

public DbSet<ReportDataV2> ReportDataV2 { get; set; }

I want to be able to treat the DataTypeName field as a discriminator column without interfering with the way ReportDataV2 already works in my code.

I tried the following, but Entity Framework detects that the data structure has changed, and if I generate the migration I see that it is trying to recreate the ReportDataV2 table.

public class OrderCountReport2Configuration : EntityTypeConfiguration<ReportDataV2>
{
    public OrderCountReportConfiguration()
        : base()
    {
         ToTable("ReportDataV2", "dbo");

         HasKey(tp => tp.ID);

        Map<OrderCountReport>(m => m.Requires("DataTypeName").HasValue("OrderCountReport"));

    }
}

   protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new OrderCountReportConfiguration());
        base.OnModelCreating(modelBuilder);
    }
}
Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • I think my problem might be that I want to use a column that is nVarchar(Max) as a discriminator column. If I run a migration the generated code has the field with length 4000 – Kirsten Nov 02 '16 at 00:12
  • http://stackoverflow.com/questions/5053335/entity-framework-ctp5-code-first-how-do-i-specify-the-type-of-the-discrimimator – Kirsten Nov 02 '16 at 00:13

1 Answers1

0

The discriminator column must have a size limit , just like an indexed column needs a size limit

Kirsten
  • 15,730
  • 41
  • 179
  • 318