Calling Find on a DBSet does not return results w/o calling ToList() first.
Example:
using (var connection = new SQLiteConnection("Data Source=:memory:"))
{
connection.Open();
var id = Guid.NewGuid();
using (var context = new TestDBSQLiteContext(connection))
{
var customer = new Customer {Id = id, SisNumber = "1234567"};
context.Customers.Add(customer);
context.SaveChanges();
}
using (var context = new TestDBSQLiteContext(connection))
{
// this should write the sis number (but does not)
Console.WriteLine(context.Customers.Find(id)?.SisNumber ?? "<NULL>");
}
using (var context = new TestDBSQLiteContext(connection))
{
var dummy = context.Customers.ToList();
// here it gets written
Console.WriteLine(context.Customers.Find(id)?.SisNumber ?? "<NULL>");
}
}
I can provide a complete test program, if required.
|