'数据表'没有定义键

时间:2015-07-14 10:41:58

标签: asp.net datatable

尝试添加新迁移时发生错误。

我已经用Google搜索了,似乎首选解决方案是在ID中添加[Key],但这在我的情况下不起作用。我怀疑错误是概念性的。这是我的模特:

namespace steer.Models
{
    public class UpFile
    {
        [Display(Name="Auðkenni")]
        public int ID { get; set; }
        [Required]
        [Display(Name="Nafn")]
        public string Name { get; set; }

        [Display(Name = "Hlaðið þann")]
        public DateTime Date { get; set; }

        [Display(Name="Tegund")]
        public string FileType { get; set; }

        [Display(Name = "Stærð (kB)")]
        public int Size { get; set; }

        public DataTable Excel { get; set; }

        public class UpFileDBContext : DbContext
        {
            public DbSet<UpFile> UpFiles { get; set; }
        }

    }
}

我只想在我的模型中添加一个简单的DataTable属性。这可能吗?

编辑:完整的错误消息。

One or more validation errors were detected during model generation:

steer.Models.DataTable: : EntityType 'DataTable' has no key defined. Define the key for this EntityType.
steer.Models.CultureInfo: : EntityType 'CultureInfo' has no key defined. Define the key for this EntityType.
steer.Models.DateTimeFormatInfo: : EntityType 'DateTimeFormatInfo' has no key defined. Define the key for this EntityType.
DataTables: EntityType: EntitySet 'DataTables' is based on type 'DataTable' that has no keys defined.
CultureInfoes: EntityType: EntitySet 'CultureInfoes' is based on type 'CultureInfo' that has no keys defined.
DateTimeFormatInfoes: EntityType: EntitySet 'DateTimeFormatInfoes' is based on type 'DateTimeFormatInfo' that has no keys defined.

0 个答案:

没有答案