I’m returning a null in my code: (the var cat line)
public class CategoryItemsViewModel
{
public ICategoriesRepository categoriesRepository;
public IEnumerable<Categories> GetCategories()
{
var cat = categoriesRepository.Categories;
return cat;
}
}
here is the interface:
namespace SportsStore.Domain.Abstract
{
public interface ICategoriesRepository
{
IQueryable<Categories> Categories { get; }
void SaveCategory(Categories category);
void DeleteCategory(Categories category);
}
}
here is the class:
namespace SportsStore.Domain.Entities
{
public class Categories
{
[Key]
public int CategoryID { get; set; }
public string CategoryName { get; set; }
}
}
What am I doing wrong?
What you have so far is fine – it’s just incomplete.
You don’t need a setter as someone else suggested either – in fact in this case it’s probably better not to have one.
You do need a concrete implementation of your interface ICategoriesRepository eg:
Then you will need to add a line to your viewmodel: