为什么我的EntityData模型无效?

时间:2016-03-04 16:40:13

标签: c# entity-framework azure

我已根据Microsoft提供的指南创建了一个azure移动应用程序。

我正在尝试更新我的数据库以反映模型,但是当我运行Add-Migration Init时,我得到:无法确定类型'theactivitynetworkService.DataObjects.Activity'的复合主键排序。使用ColumnAttribute(请参阅http://go.microsoft.com/fwlink/?LinkId=386388)或HasKey方法(请参阅http://go.microsoft.com/fwlink/?LinkId=386387)指定复合主键的顺序。

有人可以解释此错误,因为我无法理解文档如何应用于我的实例。

由于

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; }
    }

}

编辑: 这是EntityData类 - 它显示为“来自元数据”。任何建议表示赞赏!

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; }
    }
}

编辑2: 好的,如果我删除[Key]注释并运行add-migration init它可以正常工作,但update-database会抛出:Identity column 'Id' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, unencrypted, and constrained to be nonnullable.

0 个答案:

没有答案