C# (MVC,Identity)如何将ApplicationUser添加到模型中?

C# (MVC,Identity)如何将ApplicationUser添加到模型中?,c#,asp.net,asp.net-mvc,asp.net-identity,C#,Asp.net,Asp.net Mvc,Asp.net Identity,我想在MVC中做一个博客项目。因此,我在VS whit ASP.NET 4.5.1和个人用户帐户中创建了一个新项目 现在我面临的问题与下面文章中提到的完全相同: 但是我的有点深 我不知道如何在我的模型中定义“ApplicationUser”。这是我的模型: public class Article { public int Id {get; set;} . . . public string AuthorId { get; set; } publ

我想在MVC中做一个博客项目。因此,我在VS whit ASP.NET 4.5.1和个人用户帐户中创建了一个新项目

现在我面临的问题与下面文章中提到的完全相同:

但是我的有点深

我不知道如何在我的模型中定义“ApplicationUser”。这是我的模型:

public class Article {
    public int Id {get; set;}
    .
    .
    .
    public string AuthorId { get; set; }
    public virtual ApplicationUser Author { get; set; } //this line is the problem!
}
这是我非常简单的控制器:

namespace Blog.Controllers
{
    [Authorize]
    public class ArticleController : Controller
    {
        DatabaseContext db = new DatabaseContext();

        public ActionResult Index()
        {
            IEnumerable<Article> articles = db.Articles;
            return View(articles);
        }
    }
}
(请注意,上述错误中提到的所有4个类都是内置类,即它们是在创建项目期间生成的。)


我该怎么办?

您在文章类“ApplicationUser”而不是“ApplicationUser”中有一个输入错误谢谢,我在这里编辑了代码。但这不是问题所在。这只是一个键入错误。请使用
[key]
IdentityUserLogin
IdentityUserRole
注释您的密钥属性,同时此代码可能会回答问题,提供有关此代码为什么和/或如何回答问题的其他上下文,以提高其长期价值
public string AuthorId { get; set; }
[ForeignKey("AuthorId")]
public ApplicationUser Author { get; set; } //this line is the problem!
public string AuthorId { get; set; }
[ForeignKey("AuthorId")]
public ApplicationUser Author { get; set; } //this line is the problem!