2
Why does my code not recognize the method . Include("Category") in my Consoleapp? Where am I missing? Severity Code Description Project File Line Suppression State Error CS1929 'Ienumerable' does not contain a Definition for 'Include' and the best Extension method Overload '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 class.Cs
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; } } }
Cardapiorepositorio 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 Categoriarepositorio
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; } } } }
Thank you Francisco, it worked!!
– Kelly Soares