Caustix
Caustix

Reputation: 571

How can I easily store my C# data structure(XML serialiazable) into a database?

I have a C# data structure which consists of classes and collections which have references to each other. Currently I am using Serialization to store the structure in XML, which works as a handy way to save/load the structure into my application.

If I want to be able to save/load the structure into a database, is there a simple way? Should I use LINQ?

Upvotes: 0

Views: 600

Answers (3)

Paolo Tedesco
Paolo Tedesco

Reputation: 57222

Have you tried NHibernate?

EDIT: I don't know if this would be ok for you, but if you can define DB tables to hold your data structures, you could have code auto-generated using LINQ to SQL. Check ScottGu's tutorial on LINQ to SQL. If your data structures are not changing too often this could be a good way to go.

Upvotes: 0

jmservera
jmservera

Reputation: 6682

It currently depends on your needs, and the db engine you are using:

  • If you need to perform queries against the XML contents you can use a XML field (mssql and oracle do support them).
  • If you only need to store/retrieve it, just store it in a long string field (NText in sqlserver. NCLob in Oracle).

Upvotes: 1

Kane
Kane

Reputation: 16812

Just to be 100% clear LINQ has nothing to do with storing data in a database. LINQ is a language query for c# with syntax that resembles SQL.

So in order to answer your question you could look at the Entity Framework (I'd recommend this if you are using .NET 4.0) or LINQ to SQL

Upvotes: 2

Related Questions