Programming

.NET Core Entity Framework Migrations

Posted on

When you don’t want to script out your own database, Entity Framework Core has your back. When you change your database context or the models it uses, you can use a couple of commands to create and update your database to keep it in sync with your model. These examples run in the Package Manager […]

Programming

Stale Data in Entity Framework

Posted on

There is a subtle bug that you can encounter when using Entity Framework on a database where updates can happen out of band. For example, the situation I discovered this issue involves a replicated SQL database, with Entity Framework running in “read only” mode against the replication subscriber databases. The data is changed in the […]

Programming

Mocking Entity Framework DbContext and IDbSet With Rhino Mocks

Posted on

This is something that can take a little figuring out – using Rhino Mocks to mock a DbContext and the associated IDBSets. Because of this, I created a little generic method that helps a lot… private static IDbSet<T> GetDbSetTestDouble<T>(IList<T> data) where T : class { IQueryable<T> queryable = data.AsQueryable(); IDbSet<T> dbSet = MockRepository.GenerateMock<IDbSet<T>, IQueryable>(); dbSet.Stub(m […]