Why does not my code recognize the .Include ("Category") method in my ConsoleApp? Where am I going wrong? Severity Code Description Project File Line Suppression State QueryableExtensions.Include (IQueryable, string) 'requires a receiver of type' IQueryable '
using BotRepositorio.Entidades; using BotRepositorio.Repositorio; using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { CardapioRepositorio _tbCardapio = new CardapioRepositorio(); var list = _tbCardapio.Cardapio.Include("Categoria").ToList(); foreach (var item in list) { Console.WriteLine("{0} - {1} - {2} - {3} - {4}", item.ItemID, item.ItemCardapio, item.Preco, item.Categoria.CategoriaID, item.Categoria.Descricao); } Console.ReadKey(); } } }
Cardapio.cs class
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace BotRepositorio.Entidades { [Table("Cardapio")] public class Cardapio { [Key] public int ItemID { get; set; } public string ItemCardapio { get; set; } public decimal Preco { get; set; } public string UrlImagem { get; set; } public int CategoriaID { get; set; } public virtual Categoria Categoria { get; set; } } }
Class Category
using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace BotRepositorio.Entidades { [Table("Categoria")] public class Categoria { [Key] public int CategoriaID { get; set; } public string Descricao { get; set; } public string UrlImagem { get; set; } public virtual IEnumerable Cardapio { get; set; } } }
CardapioRepository class
using BotRepositorio.Entidades; using System.Collections.Generic; namespace BotRepositorio.Repositorio { public class CardapioRepositorio { private readonly DbContexto db = new DbContexto(); public IEnumerable Cardapio { get { return db.Cardapio; } } } }
Class Category Repository
using BotRepositorio.Entidades; using System.Collections.Generic; namespace BotRepositorio.Repositorio { public class CategoriaRepositorio { private readonly DbContexto db = new DbContexto(); public IEnumerable Categorias { get { return db.Categoria; } } } }