none
"Cannot create more than one clustered index on table" but I am not creating anything RRS feed

  • Question

  • Hi all, again I don't really know why I am getting this kind of message issue on my code. I am just trying to insert a data at database at tabledata that doesn't have any relationship with DespesaGerals table but everytime I run my code sharam this message shows.

    Cannot create more than one clustered index on table 'dbo.DespesaGerals'. Drop the existing clustered index 'PK_dbo.DespesaGerals' before creating another.

    Thanks for your help!

    Below the source code

    Funcionario.cs

    public partial class Funcionario : EntityData
        {
            public Funcionario()
            {
                this.DespesaList = new HashSet<Despesa>();
            }
    
            public string UserId { get; set; }
    
            public string Nome { get; set; }
            public Nullable<int> RE { get; set; }
            public string Area { get; set; }
            public Nullable<int> CentroCusto { get; set; }
            public string Site { get; set; }
            public string Gestor { get; set; }
            public string Gerente { get; set; }
            public string Banco { get; set; }
            public string Agencia { get; set; }
            public string ContaCorrente { get; set; }
    
            
            public virtual User User { get; set; }
    
            public virtual ICollection<Despesa> DespesaList {get; set;}
    
        }

    Despesa.cs

    public partial class DespesaGeral : EntityData
        {
    
            public string DespesaId { get; set; }
    
            public string Tipo { get; set; }
            public Nullable<DateTime> Data { get; set; }
            public Nullable<DateTime> Hora { get; set; }
            public string Descricao { get; set; }
            public Nullable<decimal> Valor { get; set; }
            public string ImagemRecido { get; set; }
    
            
            public virtual Despesa Despesa { get; set; }
                
    
    
        }

    MyDBContext.cs

    public partial class MobileServiceContext : DbContext
        {
            
            private const string connectionStringName = "Name=MS_TableConnectionString";
    
            public MobileServiceContext()
                : base(connectionStringName)
            {
            }
    
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.User> Users { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.Funcionario> Funcionarios { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.Despesa> Despesas { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.DespesaGeral> DespesaGerals { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.DespesaKM> DespesaKMs { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                string schema = ServiceSettingsDictionary.GetSchemaName();
                if (!string.IsNullOrEmpty(schema))
                {
                    modelBuilder.HasDefaultSchema(schema);
                }
    
                
                modelBuilder.Conventions.Add(
                    new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                        "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
    
                modelBuilder.Entity<Funcionario>()
                    .HasKey(f => new { f.Id, f.UserId });
    
                modelBuilder.Entity<User>()
                    .HasKey(u => new { u.Id, u.UserId })
                    .HasRequired<Funcionario>(f => f.Funcionario)
                    .WithRequiredPrincipal(u => u.User);
    
                modelBuilder.Entity<Despesa>()
                    .HasKey(d => new { d.Id, d.DespesaId })
                    .HasRequired<Funcionario>(f => f.Funcionario)
                    .WithMany(d => d.DespesaList)
                    .HasForeignKey(fk => new { fk.Id, fk.UserId });
    
                modelBuilder.Entity<DespesaGeral>()
                    .HasOptional<Despesa>(d => d.Despesa)
                    .WithMany(dg => dg.DespesaGealList)
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
                    
                modelBuilder.Entity<DespesaKM>()
                    .HasOptional<Despesa>(d => d.Despesa)
                    .WithMany(dg => dg.DespesaKMList)
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
    
            }
    }

    FuncionarioController.cs

    public class FuncionarioController : ApiController
        {
            public ApiServices Services { get; set; }
    
    
            // Post api/Registration User
            public HttpResponseMessage Post()
            {
                                
                using (MobileServiceContext cont = new MobileServiceContext())
                {
                    var func = new Funcionario
                    {
                        Id = Guid.NewGuid().ToString(),
                        UserId = "411612"
    
                    };
    
                    cont.Funcionarios.Add(func);
                    cont.SaveChanges();
    
    return this.Request.CreateResponse(HttpStatusCode.Created);
                }
            }
    
    
            
        }

    Monday, February 9, 2015 4:41 AM

Answers

  • Hello Fabio,

    With your provided code, it seems that you are using the Web API, not sure if this issue is caused by this project feature.

    >>  //When I run the application in DEBUG mode, I realize that the error message appear in this moment.

    Is that you mean when debug the code, when running to this convertion, it throws the exception, if it is, please have a try run a pure model code as below in console application to see if it works:

    class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                try
    
                {
    
    
                    using (MobileServiceContext db = new MobileServiceContext())
    
                    {
    
                        db.Database.CreateIfNotExists();
    
                    }
    
                    Console.ReadLine();
    
                }
    
                catch (Exception e)
    
                {
    
                    Console.WriteLine(e.Message);
    
                    Console.ReadLine();
    
                }
    
            }
    
    
        }
    
        
    
        public class RegistrationRequest
    
        {
    
    
            public String username { get; set; }
    
            public String password { get; set; }
    
    
        }
    
        public partial class User : EntityData
    
        {
    
            public string UserId { get; set; }
    
    
            public string UserName { get; set; }
    
            public string Pass { get; set; }
    
    
            public virtual Funcionario Funcionario { get; set; }
    
        }
    
        public class Funcionario : EntityData
    
        {
    
            public Funcionario()
    
            {
    
                this.DespesaList = new HashSet<Despesa>();
    
            }
    
    
            public string UserId { get; set; }
    
    
            public string Nome { get; set; }
    
            public Nullable<int> RE { get; set; }
    
    
            public virtual User User { get; set; }
    
            public virtual ICollection<Despesa> DespesaList { get; set; }
    
    
        }
    
        public partial class Despesa : EntityData
    
        {
    
    
            public Despesa()
    
            {
    
                this.DespesaGealList = new HashSet<DespesaGeral>();
    
                this.DespesaKMList = new HashSet<DespesaKM>();
    
            }
    
    
            public string DespesaId { get; set; }
    
            public string UserId { get; set; }
    
    
            public string Descritivo { get; set; }
    
            public string Motivo { get; set; }
    
    
            public virtual Funcionario Funcionario { get; set; }
    
            public virtual ICollection<DespesaGeral> DespesaGealList { get; set; }
    
            public virtual ICollection<DespesaKM> DespesaKMList { get; set; }
    
    
        }
    
        public class DespesaGeral : EntityData
    
        {
    
    
            public string DespesaId { get; set; }
    
    
            public string Tipo { get; set; }
    
            public Nullable<DateTime> Data { get; set; }
    
            public Nullable<DateTime> Hora { get; set; }
    
            public string Descricao { get; set; }
    
            public Nullable<decimal> Valor { get; set; }
    
            public string ImagemRecido { get; set; }
    
    
    
            public virtual Despesa Despesa { get; set; }
    
        }
    
        public class DespesaKM : EntityData
    
        {
    
            public string DespesaId { get; set; }
    
    
            public string Origem { get; set; }
    
            public string Destino { get; set; }
    
    
            public virtual Despesa Despesa { get; set; }
    
    
        }
    
        public partial class MobileServiceContext : DbContext
    
        {
    
            public MobileServiceContext()
    
            {
    
            }
    
    
            public System.Data.Entity.DbSet<User> Users { get; set; }
    
            public System.Data.Entity.DbSet<Funcionario> Funcionarios { get; set; }
    
            public System.Data.Entity.DbSet<Despesa> Despesas { get; set; }
    
            public System.Data.Entity.DbSet<DespesaGeral> DespesaGerals { get; set; }
    
            public System.Data.Entity.DbSet<DespesaKM> DespesaKMs { get; set; }
    
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
    
            {
    
    
                //When I run the application in DEBUG mode, I realize that the error message appear in this moment.
    
                //modelBuilder.Conventions.Add(
    
                //    new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
    
                //        "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
    
    
    
                modelBuilder.Entity<DespesaGeral>()
    
                    .Property(dg => dg.CreatedAt)
    
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
    
                    .HasColumnAnnotation("IX_createdAt",
    
                        new IndexAnnotation(
    
                            new IndexAttribute("IX_createdAt") { IsClustered = false }));
    
    
                modelBuilder.Entity<DespesaKM>()
    
                    .Property(dg => dg.CreatedAt)
    
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
    
                    .HasColumnAnnotation("IX_createdAt",
    
                        new IndexAnnotation(
    
                            new IndexAttribute("IX_createdAt") { IsClustered = false }));
    
    
    
                modelBuilder.Entity<Funcionario>()
    
                    .HasKey(f => new { f.Id, f.UserId });
    
    
                modelBuilder.Entity<User>()
    
                    .HasKey(u => new { u.Id, u.UserId })
    
                    .HasRequired<Funcionario>(f => f.Funcionario)
    
                    .WithRequiredPrincipal(u => u.User);
    
    
                modelBuilder.Entity<Despesa>()
    
                    .HasKey(d => new { d.Id, d.DespesaId })
    
                    .HasOptional<Funcionario>(f => f.Funcionario)
    
                    .WithMany(d => d.DespesaList)
    
                    .HasForeignKey(fk => new { fk.Id, fk.UserId });
    
    
                modelBuilder.Entity<DespesaKM>()
    
                    .HasOptional<Despesa>(d => d.Despesa)
    
                    .WithMany(dg => dg.DespesaKMList)
    
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
    
    
                modelBuilder.Entity<DespesaGeral>()
    
                    .HasOptional<Despesa>(d => d.Despesa)
    
                    .WithMany(dg => dg.DespesaGealList)
    
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
    
    
            }
    
        }
    
        public class EntityData
    
        {
    
            public int Id { get; set; }
    
            public DateTime CreatedAt { get; set; }
    
        }

    I comment out the convention and it would run ok in my computer. If it is caused by the WebAPi projecy, I suggest that you could post this issue to webapi related forum:

    http://forums.asp.net/1246.aspx/1?Web+API

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, February 12, 2015 9:03 AM
    Moderator

All replies

  • Hello Fabio,

    >> I am just trying to insert a data at database at tabledata that doesn't

    From your description, it is not clear when this exception occurs, is that your database already exists? Please tell us.

    For this exception, this is because in Entity Framework Code First, the Entity Framework would create the clustered-index for the primary key automatically, please check if you have add data annotation as below to any property:

    [Index("IdAndRating", IsClustered = true)]
    
    public int Rating { get; set; }
    

    Please check your code model and if it has, please remove it or keep it and remove the clustered-index for the primary key by using code first migration, for this, you could check this thread:

    https://social.msdn.microsoft.com/Forums/en-US/b390b887-9cf0-49e9-aed2-6a560fbb15fe/cannot-create-more-than-1-clustered-index-but-i-dont-have-any-other-indexes?forum=adodotnetentityframework

    If you do not have such a attribute, I do recommend you share the whole model with us, with current entities, it is hard to reproduce this issue.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 10, 2015 7:58 AM
    Moderator
  • Dear Fred Bao, I am posting the full source code to you help me understand why my project is showing this issue. As I said I really don't know what happen. I hope you could identify what it is.

    Again this is the error message: Cannot create more than one clustered index on table 'dbo.DespesaGerals'. Drop the existing clustered index 'PK_dbo.DespesaGerals' before creating another.

    Console Application: I created this console application project to run and test my CRUD implementations. In this class I'm inserting one new user and password at Users database.

    public class Program
        {
            static void Main(string[] args)
            {
             
                    try
                    {
                        Program p = new Program();
    
                        Console.WriteLine(p.PostUsuario("fsbotelho", "minhasenha1"));
                        Console.ReadLine();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
             
            }
    
    
            public string PostUsuario(string user, string senha)
            {
    
                    RegistrationController rc = new RegistrationController();
                    RegistrationRequest rr = new RegistrationRequest
                    {
                        username = user,
                        password = senha
    
                    };
    
                    return rc.Post(rr).RequestMessage.ToString();
                
            }
    
        }

    DataObjects

    RegistrationRequest: This is my attributes class for registration a new user.

    public class RegistrationRequest
        {
            
            public String username { get; set; }
            public String password { get; set; }
            
        }

    User: This is the attribute class for Users table

    public partial class User : EntityData
        {
            public string UserId { get; set; }
    
            public string UserName { get; set; }
            public string Pass { get; set; }
            
            public virtual Funcionario Funcionario { get; set; }    
        }

    Funcionario: This is attribute class for Funcionarios table 

    public class Funcionario : EntityData
        {
            public Funcionario()
            {
                this.DespesaList = new HashSet<Despesa>();
            }
    
            public string UserId { get; set; }
    
            public string Nome { get; set; }
            public Nullable<int> RE { get; set; }
            
            public virtual User User { get; set; }
    		public virtual ICollection<Despesa> DespesaList {get; set;}
    
        }

    Despesa: This is attribute class for Despesas table

    public partial class Despesa : EntityData
        {
    
            public  Despesa()
            {
                this.DespesaGealList = new HashSet<DespesaGeral>();
                this.DespesaKMList = new HashSet<DespesaKM>();
            }
            
            public string DespesaId { get; set; }
            public string UserId { get; set; }
    
            public string Descritivo { get; set; }
            public string Motivo { get; set; }
    
            public virtual Funcionario Funcionario { get; set; }
            public virtual ICollection<DespesaGeral> DespesaGealList { get; set; }
            public virtual ICollection<DespesaKM> DespesaKMList { get; set; }
       
        }

    DespesaGeral: This is attribute class for DespesaGerals table

    public class DespesaGeral : EntityData
        {
    
            public string DespesaId { get; set; }
    
            public string Tipo { get; set; }
            public Nullable<DateTime> Data { get; set; }
            public Nullable<DateTime> Hora { get; set; }
            public string Descricao { get; set; }
            public Nullable<decimal> Valor { get; set; }
            public string ImagemRecido { get; set; }
    
            
            public virtual Despesa Despesa { get; set; }
                
    
    
        

    DespesaKM: this is attribute class for DespesaKMs table

    public class DespesaKM : EntityData
        {
            public string DespesaId { get; set; }
    
            public string Origem { get; set; }
            public string Destino { get; set; }
            
            public virtual Despesa Despesa { get; set; }
    
        }

    Controllers

    RegistrationController: I created this class to insert into Users table the user and pass what I received from console application

    public class RegistrationController : ApiController
        {
            public ApiServices Services { get; set; }
    
            // Post api/Registration User
            public HttpResponseMessage Post(RegistrationRequest registrationRequest)
            {
                MobileServiceContext context = new MobileServiceContext();
                User account = context.Users.Where(a => a.UserName == registrationRequest.username).SingleOrDefault();
                if (account != null)
                {
                    return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Username already exists");
                }
                else
                {
                    byte[] salt = AutenticacaoUtils.generateSalt();
    
                    
                    var newAccount = new User
                    {
                        Id = Guid.NewGuid().ToString(),
                        UserId = "411612", 
                        UserName = registrationRequest.username,
                        Pass = registrationRequest.password,
                        
                    };
    
                    context.Users.Add(newAccount);
    
                    var f = PostFuncionario(newAccount);
                    context.Funcionarios.Add(f);
    
                    context.SaveChanges();
                    return this.Request.CreateResponse(HttpStatusCode.Created);
                }
            }
    
            private Funcionario PostFuncionario(User user)
            {
                var func = new Funcionario
                {
                    User = user,
                };
    
                return func;
            }
        }


    Models

    MobileServiceContext: Please take a look at my comment inside OnModelCreating class.

    public partial class MobileServiceContext : DbContext
        {
            private const string connectionStringName = "Name=MS_TableConnectionString";
    
            public MobileServiceContext()
                : base(connectionStringName)
            {
            }
    
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.User> Users { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.Funcionario> Funcionarios { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.Despesa> Despesas { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.DespesaGeral> DespesaGerals { get; set; }
            public System.Data.Entity.DbSet<ProjetoMobileService.DataObjects.DespesaKM> DespesaKMs { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                string schema = ServiceSettingsDictionary.GetSchemaName();
                if (!string.IsNullOrEmpty(schema))
                {
                    modelBuilder.HasDefaultSchema(schema);
                }
    
                //When I run the application in DEBUG mode, I realize that the error message appear in this moment.
                modelBuilder.Conventions.Add(
                    new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                        "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
    
                
                modelBuilder.Entity<DespesaGeral>()
                    .Property(dg => dg.CreatedAt)
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
                    .HasColumnAnnotation("IX_createdAt",
                        new IndexAnnotation(
                            new IndexAttribute("IX_createdAt") { IsClustered = false }));
    
                modelBuilder.Entity<DespesaKM>()
                    .Property(dg => dg.CreatedAt)
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
                    .HasColumnAnnotation("IX_createdAt",
                        new IndexAnnotation(
                            new IndexAttribute("IX_createdAt") { IsClustered = false }));
                
    
                modelBuilder.Entity<Funcionario>()
                    .HasKey(f => new { f.Id, f.UserId });
    
                modelBuilder.Entity<User>()
                    .HasKey(u => new { u.Id, u.UserId })
                    .HasRequired<Funcionario>(f => f.Funcionario)
                    .WithRequiredPrincipal(u => u.User);
    
                modelBuilder.Entity<Despesa>()
                    .HasKey(d => new { d.Id, d.DespesaId })
                    .HasOptional<Funcionario>(f => f.Funcionario)
                    .WithMany(d => d.DespesaList)
                    .HasForeignKey(fk => new { fk.Id, fk.UserId });
    
                modelBuilder.Entity<DespesaKM>()
                    .HasOptional<Despesa>(d => d.Despesa)
                    .WithMany(dg => dg.DespesaKMList)
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
                
                modelBuilder.Entity<DespesaGeral>()
                    .HasOptional<Despesa>(d => d.Despesa)
                    .WithMany(dg => dg.DespesaGealList)
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
      
            }
        
    Just to let you know, one User only could have one Funcionario. One Funcionario could have many Despesas. Despesas could have many DespesaGerals and also DespesaKMs.

    Hint 1 - When I run the project from starting azure mobile service debug mode, I can post api/registration controller with any error.

    Hint 2 - When I run the project from console application using the same api/registration controller I got the error message described before.

    Again thank you so much for your time with this problem.

    Fabio Botelho

    Thursday, February 12, 2015 2:12 AM
  • Hello Fabio,

    With your provided code, it seems that you are using the Web API, not sure if this issue is caused by this project feature.

    >>  //When I run the application in DEBUG mode, I realize that the error message appear in this moment.

    Is that you mean when debug the code, when running to this convertion, it throws the exception, if it is, please have a try run a pure model code as below in console application to see if it works:

    class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                try
    
                {
    
    
                    using (MobileServiceContext db = new MobileServiceContext())
    
                    {
    
                        db.Database.CreateIfNotExists();
    
                    }
    
                    Console.ReadLine();
    
                }
    
                catch (Exception e)
    
                {
    
                    Console.WriteLine(e.Message);
    
                    Console.ReadLine();
    
                }
    
            }
    
    
        }
    
        
    
        public class RegistrationRequest
    
        {
    
    
            public String username { get; set; }
    
            public String password { get; set; }
    
    
        }
    
        public partial class User : EntityData
    
        {
    
            public string UserId { get; set; }
    
    
            public string UserName { get; set; }
    
            public string Pass { get; set; }
    
    
            public virtual Funcionario Funcionario { get; set; }
    
        }
    
        public class Funcionario : EntityData
    
        {
    
            public Funcionario()
    
            {
    
                this.DespesaList = new HashSet<Despesa>();
    
            }
    
    
            public string UserId { get; set; }
    
    
            public string Nome { get; set; }
    
            public Nullable<int> RE { get; set; }
    
    
            public virtual User User { get; set; }
    
            public virtual ICollection<Despesa> DespesaList { get; set; }
    
    
        }
    
        public partial class Despesa : EntityData
    
        {
    
    
            public Despesa()
    
            {
    
                this.DespesaGealList = new HashSet<DespesaGeral>();
    
                this.DespesaKMList = new HashSet<DespesaKM>();
    
            }
    
    
            public string DespesaId { get; set; }
    
            public string UserId { get; set; }
    
    
            public string Descritivo { get; set; }
    
            public string Motivo { get; set; }
    
    
            public virtual Funcionario Funcionario { get; set; }
    
            public virtual ICollection<DespesaGeral> DespesaGealList { get; set; }
    
            public virtual ICollection<DespesaKM> DespesaKMList { get; set; }
    
    
        }
    
        public class DespesaGeral : EntityData
    
        {
    
    
            public string DespesaId { get; set; }
    
    
            public string Tipo { get; set; }
    
            public Nullable<DateTime> Data { get; set; }
    
            public Nullable<DateTime> Hora { get; set; }
    
            public string Descricao { get; set; }
    
            public Nullable<decimal> Valor { get; set; }
    
            public string ImagemRecido { get; set; }
    
    
    
            public virtual Despesa Despesa { get; set; }
    
        }
    
        public class DespesaKM : EntityData
    
        {
    
            public string DespesaId { get; set; }
    
    
            public string Origem { get; set; }
    
            public string Destino { get; set; }
    
    
            public virtual Despesa Despesa { get; set; }
    
    
        }
    
        public partial class MobileServiceContext : DbContext
    
        {
    
            public MobileServiceContext()
    
            {
    
            }
    
    
            public System.Data.Entity.DbSet<User> Users { get; set; }
    
            public System.Data.Entity.DbSet<Funcionario> Funcionarios { get; set; }
    
            public System.Data.Entity.DbSet<Despesa> Despesas { get; set; }
    
            public System.Data.Entity.DbSet<DespesaGeral> DespesaGerals { get; set; }
    
            public System.Data.Entity.DbSet<DespesaKM> DespesaKMs { get; set; }
    
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
    
            {
    
    
                //When I run the application in DEBUG mode, I realize that the error message appear in this moment.
    
                //modelBuilder.Conventions.Add(
    
                //    new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
    
                //        "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
    
    
    
                modelBuilder.Entity<DespesaGeral>()
    
                    .Property(dg => dg.CreatedAt)
    
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
    
                    .HasColumnAnnotation("IX_createdAt",
    
                        new IndexAnnotation(
    
                            new IndexAttribute("IX_createdAt") { IsClustered = false }));
    
    
                modelBuilder.Entity<DespesaKM>()
    
                    .Property(dg => dg.CreatedAt)
    
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
    
                    .HasColumnAnnotation("IX_createdAt",
    
                        new IndexAnnotation(
    
                            new IndexAttribute("IX_createdAt") { IsClustered = false }));
    
    
    
                modelBuilder.Entity<Funcionario>()
    
                    .HasKey(f => new { f.Id, f.UserId });
    
    
                modelBuilder.Entity<User>()
    
                    .HasKey(u => new { u.Id, u.UserId })
    
                    .HasRequired<Funcionario>(f => f.Funcionario)
    
                    .WithRequiredPrincipal(u => u.User);
    
    
                modelBuilder.Entity<Despesa>()
    
                    .HasKey(d => new { d.Id, d.DespesaId })
    
                    .HasOptional<Funcionario>(f => f.Funcionario)
    
                    .WithMany(d => d.DespesaList)
    
                    .HasForeignKey(fk => new { fk.Id, fk.UserId });
    
    
                modelBuilder.Entity<DespesaKM>()
    
                    .HasOptional<Despesa>(d => d.Despesa)
    
                    .WithMany(dg => dg.DespesaKMList)
    
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
    
    
                modelBuilder.Entity<DespesaGeral>()
    
                    .HasOptional<Despesa>(d => d.Despesa)
    
                    .WithMany(dg => dg.DespesaGealList)
    
                    .HasForeignKey(fk => new { fk.Id, fk.DespesaId });
    
    
            }
    
        }
    
        public class EntityData
    
        {
    
            public int Id { get; set; }
    
            public DateTime CreatedAt { get; set; }
    
        }

    I comment out the convention and it would run ok in my computer. If it is caused by the WebAPi projecy, I suggest that you could post this issue to webapi related forum:

    http://forums.asp.net/1246.aspx/1?Web+API

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, February 12, 2015 9:03 AM
    Moderator