C# 为什么我的EntityData模型无效?

C# 为什么我的EntityData模型无效?,c#,entity-framework,azure,C#,Entity Framework,Azure,我已经按照微软提供的指南创建了一个azure移动应用程序 我正在尝试更新数据库以反映模型,但当我运行Add Migration Init时,我得到:无法确定“theactivitynetworkService.DataObjects.Activity”类型的复合主键顺序。使用ColumnAttribute(请参阅)或HasKey方法(请参阅)指定复合主键的顺序 有人能解释一下这个错误吗?因为我不明白这些文档是如何应用到我的实例中的 谢谢 using Microsoft.Azure.Mobile.

我已经按照微软提供的指南创建了一个azure移动应用程序

我正在尝试更新数据库以反映模型,但当我运行Add Migration Init时,我得到:无法确定“theactivitynetworkService.DataObjects.Activity”类型的复合主键顺序。使用ColumnAttribute(请参阅)或HasKey方法(请参阅)指定复合主键的顺序

有人能解释一下这个错误吗?因为我不明白这些文档是如何应用到我的实例中的

谢谢

using Microsoft.Azure.Mobile.Server;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace theactivitynetworkService.DataObjects
{
    public class Activity : EntityData
    {
        public int ActivityId { get; set; }
        public Activity() { }
        public string ActivityName { get; set; }
        public virtual UserProfile UserProfile { get; set; }
    }

    public class UserProfile : EntityData
    {
        public int UserProfileId { get; set; }
        public UserProfile()
        {
            Activities = new List<Activity>();
        }
        public string UserProfileBio { get; set; }
        public string UserProfileLastLocation { get; set; }
        public virtual ICollection<Activity> Activities { get; set; }
    }

}
编辑2:
好的,如果我删除
[Key]
注释并运行
add migration init
它可以正常工作,但是
更新数据库
抛出:
标识列“Id”必须是数据类型int、bigint、smallint、tinyint或小数或小数,小数位数为0,未加密,并且被限制为不可为空。

也许您的EntityData类已经定义了一个键?谢谢,发现了它-我看到它已经存在了。如果我删除自己的密钥,它会抱怨密钥不是int类型-在上面的示例中如何更改它的类型?看起来它应该是
string
“按设计”好的,所以如果我删除[key]注释并运行add migration init,它可以正常工作,但更新数据库抛出:标识列“Id”必须是int、bigint类型的数据,smallint、tinyint或小数或数字,小数位数为0,未加密,并限制为不可为空。您的Id(和其他一些字段)来自抽象类,因此您只需要自己的属性。这里有一个关于迁移问题的链接。
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.Azure.Mobile.Server.Tables;

namespace Microsoft.Azure.Mobile.Server
{
    //
    // Summary:
    //     An abstract implementation of the Microsoft.Azure.Mobile.Server.Tables.ITableData
    //     interface indicating how the system properties for a given table data model are
    //     to be serialized when communicating with clients when using Entity Framework
    //     for accessing the backend store. The uniform serialization of system properties
    //     ensures that the clients can process the system properties uniformly across platforms.
    //     Concrete entity framework models can derive from this base class in order to
    //     support the system properties.
    public abstract class EntityData : ITableData
    {
        protected EntityData();

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Index(IsClustered = true)]
        [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; }
    }
}