我是 MVC 和 C# 的新手。我只是偶然发现它,发现它很有趣。我遇到了一个不允许我继续的问题。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; 
namespace MyHotel.Models
{
    public class AccountTypes
    {
        public int AccountTypeID { get; set; }
        public string AccountTypeName { get; set; }
    }
}
之后我创建了控制器和视图。
为此,我不断收到此错误:
在模型生成期间检测到一个或多个验证错误:
System.Data.Edm.EdmEntityType: : EntityType 'AccountTypes' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet "AccountTypes" is based on type "AccountTypes" that has no keys defined.
我在谷歌上搜索到答案是添加   [Key]的,public int AccountTypeID { get; set; }所以它看起来像这样:
namespace MyHotel.Models
{
    public class AccountTypes
    {
        [Key]
        public int AccountTypeID { get; set; }
        public string AccountTypeName { get; set; }
    }
}
但直到现在都没有结果。注意:我使用的是 MVC 4