Using viewModel error: Cannot implicitly convert type

Jun 23 2017 3:56 AM
Hello,
 
Direct error. I have a  ViewModel class called StoreLocationViewModel. Here is the definition.
 

  • public class StoreLocationViewModel
  • {
  • public Store Stores { get; set; }
  • public List<Department> Departments { get; set; }
  • }
  •  
    Inside the Controller I'm trying to initialize the ViewModel
    1. public async Task<IActionResult> Index()  
    2.         {  
    3.             var viewModel = new StoreLocationViewModel();  
    4.             viewModel.Stores = _context.Stores;  
    However I get this error:
     
    Cannot implicitly convert type 'Microsoft.EntityFrameworkCore.DbSet<Application.Models.Store>' into 'Applications.Models.Store'.
     
    This is the first time encountering this error and it's too specific in order to find documentation online. Can someone please explain me what does it mean?. Thanks in advance! 

    Answers (3)