Error after migrations (backend .Net)

1

My backend is built in .NET, and by including a certain table in the solution, I get the following error:

  

Can not create more than one clustered index on table 'dbo.Favorit'.   Drop the existing clustered index 'PK_dbo.Favorit' before   creating another.

What would that be? And how to solve? Thanks!

This code was generated after the command Add-Migration CreateFavorit and update-database :

namespace appService.Migrations
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Infrastructure.Annotations;
    using System.Data.Entity.Migrations;

    public partial class CreateFavorit : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Favorit",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128,
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    "ServiceTableColumn",
                                    new AnnotationValues(oldValue: null, newValue: "Id")
                                },
                            }),
                        Nome = c.String(),
                        Lat_dest = c.Double(nullable: false),
                        Lon_dest = c.Double(nullable: false),
                        Id_usuario = c.String(),
                        Endereco = c.String(),
                        MeioTransporte = c.String(),
                        Id_usuario_2 = c.String(),
                        Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion",
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    "ServiceTableColumn",
                                    new AnnotationValues(oldValue: null, newValue: "Version")
                                },
                            }),
                        CreatedAt = c.DateTimeOffset(nullable: false, precision: 7,
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    "ServiceTableColumn",
                                    new AnnotationValues(oldValue: null, newValue: "CreatedAt")
                                },
                            }),
                        UpdatedAt = c.DateTimeOffset(precision: 7,
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    "ServiceTableColumn",
                                    new AnnotationValues(oldValue: null, newValue: "UpdatedAt")
                                },
                            }),
                        Deleted = c.Boolean(nullable: false,
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    "ServiceTableColumn",
                                    new AnnotationValues(oldValue: null, newValue: "Deleted")
                                },
                            }),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.CreatedAt, clustered: true);

        }

        public override void Down()
        {
            DropIndex("dbo.Favorit", new[] { "CreatedAt" });
            DropTable("dbo.Favorit",
                removedColumnAnnotations: new Dictionary<string, IDictionary<string, object>>
                {
                    {
                        "CreatedAt",
                        new Dictionary<string, object>
                        {
                            { "ServiceTableColumn", "CreatedAt" },
                        }
                    },
                    {
                        "Deleted",
                        new Dictionary<string, object>
                        {
                            { "ServiceTableColumn", "Deleted" },
                        }
                    },
                    {
                        "Id",
                        new Dictionary<string, object>
                        {
                            { "ServiceTableColumn", "Id" },
                        }
                    },
                    {
                        "UpdatedAt",
                        new Dictionary<string, object>
                        {
                            { "ServiceTableColumn", "UpdatedAt" },
                        }
                    },
                    {
                        "Version",
                        new Dictionary<string, object>
                        {
                            { "ServiceTableColumn", "Version" },
                        }
                    },
                });
        }
    }
}

I do not know if it is pertinent, but the database is SQLServer, microsft-azure the server.

    
asked by anonymous 29.01.2017 / 21:18

1 answer

0
  

The error message is caused by the Entity Framework not having a   annotation to create a clustered index, which is not a primary key.   The mobile SDK manually creates the correct SQL statements to set the   CreateAt, as a non-primary key cluster index.

Then solved by putting the following code in the Configuration.cs, which is in Migrations:

public Configuration()
{
   AutomaticMigrationsEnabled = false;
   SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
}

Added setSqlGenerator ....

    
01.02.2017 / 13:00