views:

257

answers:

4

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!

+1  A: 

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#.

Anders Abel
Thanks. I think the main reason I've been hesitant to use a database is concern about simplicity, this makes me feel a little better about that.
Joel
A: 

Database is the way to go, definetely. Use an object-relational mapper to talk to a database, this will probably cover 99% of your needs at the beginning.

I prefer to keep the XML-serialization for the scenarios requiring different process intercommunication.

Yacoder
A: 

It really depends on what you need to achieve. Databases have a place, but flat files are also perfectly fine for data (via serialization).

So; what problems is the xml giving you? If you can answer that, then you'll know what the pain points are that you want to address. You mention "game", and indeed flat files tend to be more suitable (assuming you want minimum overhead etc), but either would normally do fine. Binary serialization might be more efficient in terms of CPU and disk (but I don't recommend BinaryFormatter - it will bite you when you change the types).

I'm not anti-database (far from it) - I just wanted to present a balanced viewpoint ;-p

Marc Gravell
The main problem I'm getting from the XML is circular references. Elements (like game items) are stored in sources, and also store a reference to the reference to the source they come from. Thanks for giving some other options!
Joel
@Joel - things like DataContractSerializer / NetDataContractSerializer support "graph" mode, which preserves object references (even circular ones). I must add a graph mode to pb-net ;-p
Marc Gravell
A: 

You could use an object database (such as db4o). The benefits include: type safety, no ORM, indexed information...

Goran