Search code examples
c#.netdatabasefilefile-manipulation

Storing and loading program data, C# WPF


I'm writing a utility program with C# in WPF that allows users to create role-playing scenarios, including monsters, items, characters, etc.

The user will create or import the elements (monsters, etc) and then use the imported elements to create scenarios. Everything used by the program is created within the program, so I don't have any pre-defined data I'll be accessing.

Here's my question - what's the best way to store and load the data?

Currently, I'm using XML serialization to serialize the objects to XML files and reload them later. This is kind of clunky, and I'm wondering if a database would be more effective - the data is definitely relational (monsters have items, maps have monsters, etc), and there could be dozens or hundreds of entries.

I don't need actual lines of code or methods to use, just an idea of what kind of file storage/retrieval would usually be used in this situation (in .NET).

Thanks!


Solution

  • As you said yourself: The data is relational so a relational database will probably help. Using Sql Server Compact you can have simple files, which are named whatever you want, that you load into Sql Server when opening. That way you won't have to administer a traditional database server and the user won't even know there is a database involved.

    To access the data I'm personally very fond of Linq-to-Sql, which gives type-safe querying directly in C#.