How to use EF Core Code First in Azure Synapse

Asked

Viewed 25 times

1

I’m trying to use migrations to manage database schemas with Entity Framework Core and C# in Azure Synapse, when I run the update-database command I get an error message as described below:

Enforced unique constraints are not supported. To create an unenforced unique constraint you must include the NOT ENFORCED syntax as part of your statement.

This error occurs because Azure Synapse does not accept the use of PRIMARY KEY without it being accompanied by NONCLUSTERED and NOT ENFORCED. The script below works perfectly when running on msqlms:

CREATE TABLE dbo.sample_table
(
    c1 int IDENTITY(1,1) NOT NULL,
    c2 char(10) NULL,
    c3 datetime NULL
)

ALTER TABLE t1 ADD CONSTRAINT PK_t1_c1 PRIMARY KEY NONCLUSTERED (c1) NOT ENFORCED

To include NONCLUSTERED by EF mapping just set Isclustered(false) as an example.

public class ManifestationMap : IEntityTypeConfiguration<Manifestation>
{
    public void Configure(EntityTypeBuilder<Manifestation> builder)
    {
        builder.ToTable("Manifestation");

        builder.HasKey(prop => prop.Id)
           .IsClustered(false); // Include NONCLUSTERED 
        ...

I have not found any solution to include NOT ENFORCED by EF.

Note: I don’t have this problem when using Azure SQL Server, nor when using Sql Server installed locally, only in Azure Synapse (Sql Server DW).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.