I have MVC framework User Table and my own Community Table. I also have a relationship CommunityUser table. I am virtually connecting CommunityUser table with community Table. Here is my Community class
public class Community
{
[Key]
public int CommunityID { get; set; }
[Required]
public string CommunityName { get; set; }
[Required]
public string CommunityDomain { get; set; }
public string CommunityAbout { get; set; }
public string CommunityLogo { get; set; }
public int PrivacyID { get; set; }
public string CommunityAdmin { get; set; }
public virtual PrivacyLevel PrivacyLevel { get; set; }
public virtual ICollection<CommunityUser> CommunityUsers { get; set; }
public Community()
{
CommunityUsers = new Collection<CommunityUser>();
}
}
I want to use User Table and Community User Table on my index page. I have created a ProfileDataViewModel having these two tables.
public class ProfileDataViewModel
{
public ApplicationUser User { get; set; }
public List<CommunityUser> CommunitiesList { get; set; }
}
Now when I am using this view model on my index function, it is throwing an exception. Here is my index function
public ActionResult Index()
{
var thisUser = db.Users.Where(u => u.UserName == User.Identity.Name).SingleOrDefault();
var myDashboard = new ProfileDataViewModel()
{
User = thisUser,
CommunitiesList = db.CommunityUsers.Include(x => x.Community).Where(u => u.UserID==thisUser.Id).ToList()
};
return View(myDashboard);
}
What I have tried:
when I am using this view model on my index function, it is throwing an exception. Here is my index function