I want to do a Blog project in MVC. so i created a new project in VS whit ASP.NET 4.5.1 and Individual User Accounts.
Now I'm facing exactly the same problem as mentioned in article below:
ASP.NET MVC 5 - Identity. How to get current ApplicationUser
But mine is a bit deeper!
I don't know how to define a "ApplicationUser" in my Model. this is my Model:
public class Article {
public int Id {get; set;}
.
.
.
public string AuthorId { get; set; }
public virtual ApplicationUser Author { get; set; } //this line is the problem!
}
This is my very simple Controller:
namespace Blog.Controllers
{
[Authorize]
public class ArticleController : Controller
{
DatabaseContext db = new DatabaseContext();
public ActionResult Index()
{
IEnumerable<Article> articles = db.Articles;
return View(articles);
}
}
}
And i always get this set of errors:
Blog.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
Blog.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
(Please note that all the 4 classes mentioned in errors above are built-in classes, i.e. they were built during creation of project.)
What should i do?