.NET Dual persistence architecture

I ran into the problem of writing an object persistence mechanism that serializes / deserializes an SQL database and XML files.

To illustrate, suppose I have a graph of objects with a single root object. It can be, for example, a β€œtree” that has all kinds of child objects - leaves, branches, nuts, squirrels, birds, etc.

I need a proposal for an architecture that easily moves between loading and saving a β€œtree” from a file and / or database. It should be able to load the "tree" from the file and save it in the database or vice versa.

I am currently using the Entity Framework for my persistence of SQL, and I am quite satisfied with this. For XML, I use XDocument, which I also really like, but I wonder if there is some kind of structure that already does all this.

+4
source share
3 answers

If you do not want to query your objects on Sql Server (or there are other sources that can update / manage relational data), using EF to convert to a relationship scheme is a bit overkill. If all you want to do is save the graph of objects in different environments, you should consider time serialization or DataContractSerializer. Essentially, you get binary data or XML that you can flush to any medium, including Sql Server. This will free you from changing the relationship scheme in the sql server when changing object structures. However, you should consider versioning your objects when moving from a serialization method.

+1
source

You can try using the old but very nice XmlSerializer .

ps. you need to keep track of what the Entity Framework may require when loading an object that you serialized into an XML file.

0
source

Are there any strict requirements for objects that are saved in XML format? If not, another option would be to use SQLite ( http://sqlite.phxsoftware.com/ ) with an entity infrastructure when you need a permanent local / file system.

0
source

All Articles