Tag Archives: Entity Framework

Entity Framework Mocking template with IDisposable implementation

I’m working on a C#/.NET StackOverflow clone and wanted to create mock data contexts for unit testing with Entity Framework.

I found a great T4 template that does this from Rab Hallett’s blog, but it did not include the IDisposable interfaces used by the .NET ObjectContext.

I’ve modified the template to include these additions to the generated Mock context so that I can now use the interface in a using block.

            using (var db = DataContextFactory.CreateContentContext(_isMock))
            { //actual code goes here

The entire T4 template (ContentModelGenerator.Context.tt) is on my bitbucket if you want to use it.

Target SQL Server and SQL CE with the same Entity Framework objects while using Sync Framework

When developing a sometimes-disconnected application in .NET, you have the ability to create a “local data cache” (Sql CE file) and then synchronize this local database with a server database periodically (when connected) to keep the data relevant.

Of course to actually interact with the data from your .NET application, you will want to create a data model with Entity Framework. There are a few tricks that can make the whole process much simpler.
Continue reading

AccessViolationException, EntryPointNotFoundException, and Change Tracking Error on SyncAgent.Synchronize()

Recently I was working on a data-driven application which needed to continue operating in sometimes-disconnected environments. In theory, this is a fairly simple problem to solve with .NET Sync Framework using a “Local Data Cache” implementation of SQL Server CE file and SQL Server database–a solution that I have implemented several times in the past.

Never have I had to jump through so many crazy hoops.
Continue reading