Reputation: 845
Trying to use Linq and the Entity Framework to make a super-simple lists database. The query runs, but it does not return the data I enter into it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using static System.Console;
namespace CheckList
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Building the list.");
using (var db = new ListContext())
{
ListItem socks = new ListItem() { Title = "Get Socks" };
db.ListItems.Add(socks);
Here is the actual query:
var queryresults = from item in db.ListItems
orderby item.Title
select item;
But the foreach
loop doesn't print out anything:
WriteLine("Printing out the list:");
foreach (var item in queryresults)
{
WriteLine("Item's name:");
WriteLine(item.Title);
}
The rest:
}
WriteLine("All done.");
Console.Read();
}
}
}
I've tried to simplify as much as possible, but I cannot seem to get the results to show up. What is my mistake here?
Upvotes: 1
Views: 55