Error While Enabling Code-First Migrations On Mobile Services Database

前端 未结 5 1669
你的背包
你的背包 2021-02-07 17:12

I have an Azure Mobile Services project (C# backend) that I recently created and attached to an Azure SQL database. I have been trying to enable Code-First Migrations on that ba

5条回答
  •  名媛妹妹
    2021-02-07 17:52

    I just had the same issue.

    It is caused by the definition of EntityData that is our base class:

    public class OrgTest : EntityData
    {
        public string Prop1 { get; set; }
    }
    

    I replaced EntityData with my own implementation "CustomEntity" where I removed the attribute [Index(IsClustered = true)] on the CreatedAt column:

    public abstract class CustomEntity : ITableData
    {
       // protected CustomEntity();
    
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [TableColumn(TableColumnType.CreatedAt)]
        public DateTimeOffset? CreatedAt { get; set; }
        [TableColumn(TableColumnType.Deleted)]
        public bool Deleted { get; set; }
        [Key]   
        [TableColumn(TableColumnType.Id)]
        public string Id { get; set; }
        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        [TableColumn(TableColumnType.UpdatedAt)]
        public DateTimeOffset? UpdatedAt { get; set; }
        [TableColumn(TableColumnType.Version)]
        [Timestamp]
        public byte[] Version { get; set; }
    } 
    

    and now I inherit from this one:

    public class OrgTest : CustomEntity   // EntityData
    {
        public string Prop1 { get; set; }
    }
    

    Probably I will have troubles further on, but for the time being I can create my model! Hope you can also start like this!

提交回复
热议问题