C# &引用;EntityType';用户配置文件';“未定义密钥”;但是我定义了一个键,它没有';调试时不会发生这种情况

C# &引用;EntityType';用户配置文件';“未定义密钥”;但是我定义了一个键,它没有';调试时不会发生这种情况,c#,.net,entity-framework,C#,.net,Entity Framework,我有一个基于标准Internet应用程序模板的ASP.NET MVC 4 web应用程序。我创建了一个单独的类库,其中包含了我所有的数据库类,并将“UserProfile”类移到了那里,并对其进行了一些调整,如下所示: [Table("UserProfile")] public class UserProfile { [Key] [HiddenInput(DisplayValue = false)] [DatabaseGeneratedAttribute(Database

我有一个基于标准Internet应用程序模板的ASP.NET MVC 4 web应用程序。我创建了一个单独的类库,其中包含了我所有的数据库类,并将“UserProfile”类移到了那里,并对其进行了一些调整,如下所示:

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    [StringLength(200)]
    [Display(Name = "Email Address")]
    [Required(ErrorMessage = "Please enter your email address")]
    [RegularExpression(@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$", ErrorMessage = "Please enter a valid Email address")]
    public string UserName { get; set; }

    [StringLength(200)]
    public string Name { get; set; }
}
我在我的web应用程序中使用这个类没有问题,而且它已经运行了好几个月了

昨天,我开始编写一个小型助手控制台应用程序,它需要更新与web应用程序位于同一数据库中的表。我已经添加了对数据库类库的引用,当我在有或没有VisualStudio调试器的dev PC上运行应用程序时,一切都正常

但是,当我将应用程序复制到web服务器并从那里运行它时,会出现以下错误:

Unhandled Exception: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:

\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'UserProfile' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'UserProfiles' is based on type 'UserProfile' that has no keys defined.
我已经删除了对EntityFramework的所有引用,并使用nuget重新安装了它。我已经尝试了框架的5.0.0和6.0.1版本。谷歌的每一个错误结果都会让我看到一些帖子,上面说要用[Key]属性装饰UserId属性,但正如你所看到的,我已经有了这个属性(事实上,默认情况下就是这样)


有什么好主意吗?它让我发疯了。

我设法让它工作起来了

我必须将对System.Web.Mvc的引用设置为“Copy Local”,以便将其包含在包含可执行文件等的文件夹中

我假设在我的开发电脑上有一个DLL的全局副本,它没有安装在服务器机器上,但是它可以工作,所以我现在就可以继续了