I have followed the book of Adam Freeman to learn about ASP.NET MVC 5. I have implemented the repository pattern as described in the book. I'm using WHERE and log the SQL commands with the SQL-EventProfiler, then I will see no WHERE condition.
This is my example code, for the repository I have used Ninject:
public interface IHelpRepository {
IEnumerable<Help> Helps { get; }
}
public class HelpRepository : IHelpRepository {
private HelpDBContext context = new HelpDBContext();
public IEnumerable<Help> Helps {
get { return context.Helps; }
}
}
public class Help {
[Required]
[Key]
public int Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public string Description { get; set; }
}
public class HelpController : Controller {
private IHelpRepository HelpRepository;
public HelpController (IHelpRepository helpRepository) {
this.HelpRepository= helpRepository;
}
public ActionResult HelpDescription(int Id) {
Help help = helpRepository.Helps.Where(h => h.Id == Id).SingleOrDefault<Help>();
return View("HelpDescription", help);
}
}
The resulting SQL-Command (XEventProfiler):
SELECT [Extent1].[Id] AS [Id], [Extent1].[Title] AS [Title], [Extent1].[Description] AS [Description] FROM [dbo].[Helps] AS [Extent1]
Why is the WHERE not included in the resulting SQL command?