Hey Folks,
I've got a slight problem when using a generic repository with EF4. First let me show you the code I use to access a collection of objects (this is code in the generic reposiroy):
public IEnumerable<T> FindAll<T>() where T : class
{
return ObjectContext.CreateObjectSet<T>();
}
Below is an example of this code being invoked for a repository of type Book
_returnedBooks = _dataContext.FindAll<Book>()
.Where(b => b.Title == _editedtitle && b.Description == _editedDescription && b.ImageUrl == _editedImageUrl);
The code above shows me querying the data context for a book that has the properties that match values I used to edited a book previously (hence the _edited prefix). But once I'd edited this book, I did not call Save Changes on the data context.
And there is the problem, even though I haven't saved changes, the FindAll (in this case book) returns the book with edited values. However, when I inspect the DbSet (required to register the class for use with Code First), it is not in that collection.
So, I've not managed to track down any documentation for this behaviour, or whether I myself and missing the obvious.
Help meeeeeeeeeeeeeeeeeeeeeeeee :)