Looking at my fledgling project I can already see that there's a good chance that I'll need objects that will contain other objects, all of which need to be referenced to each other - in short, a classic database scenario. And while other platforms have embraced the lovely lightweight database framework that is SQLite... Microsoft hasn't. Quite.
Looking at Nuget I can see more SQLite .NET wrappers than I can shake a stick at, which makes it very hard to decide which one to go with that will be around for the long term. However, there's another possibility. Remember that I said 'Quite' at the end of the previous paragraph? That's because Microsoft is going to offer SQLite support as part of Entity Framework 7 - but that is currently only available as a pre-release. Still, it seems like the best bet for now, and since I'm curious about it anyway, I'll take that route.
To get started, I'll be perusing the (sparse) EF7 documentation at ef.readthedocs.org/en/latest/index.html, but I'll do a quick recap here, for your enjoyment. I'm working with an Universal Windows project, so I
- Add the following application specific runtime directive to my Default.rd.xml file (found under the project properties): <Type Name="System.Collections.ArrayList" Dynamic="Required All" />. The documentation says that this will become unnecessary at a later point, but for now, in it goes.
- Install the NuGet packages for EntityFramework.SQLite and EntityFramework.Commands. both are pre-release, so make sure you use the -pre option or tick the box that allows you to search pre-release packages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuesterContext : DbContext | |
{ | |
public DbSet<Location> Locations { get; set; } | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
optionsBuilder.UseSqlite(@"Filename=Quester.db"); | |
} | |
} |
Now, I can't see much to test in my class itself, but I do want to test that I can do at least basic CRUD operations with my new data context. I don't think those tests can be classified as unit tests, but hey, they're going to be useful, so I'm gonna add them and worry about the semantics another time.
Coming up: Testing CRUD operations
No comments:
Post a Comment