I have been looking into using the Entity Framework in my C# game server to make querying easier. I am a huge fan of type safety, and the Entity Framework does a great job at automating most of the boilerplate code. Though I am not quite sure how to go about utilizing some of the components, namely the ObjectContext.
The server uses quite a lot of threading, so thread safety is a concern. Right now I just use a custom pool for executing queries. Without going into much detail, each query works in the fashion of:
- Grab a DbConnection
- Grab a DbCommand
- Allow for the query class to set the parameters
- Execute the DbCommand
- Allow for the query class to handle the query result, if any
- Free the DbCommand
- Free the DbConnection
It is very clean, fast, and safe, but the problem is that creating queries is a bit of a hassle, and I have to manually generate and update "container classes" if I want the type safety. This is why I have turned to the Entity Framework.
This all works great with using just the DbConnection and DbCommand since there is no concerns about which DbConnection/Command performs queries for which object or anything.
Anyways, I don't really know how to explain it much more without imposing restrictions. Doing something like executing a query every time I would normally with the DbConnection/Command, saving it, and disposing the ObjectContext just adds too much overhead when I really don't need the database to be updated so frequently.
How would you go about utilizing the Entity Framework for a game server that doesn't have a high demand on the database being immediately and constantly up-to-date?