49

Can someone point me to a good tutorial explaining the Entity Framework using an XML file instead of a database? I have seen some good tutorials with SQL databases, but I can't make the leap to an XML file.

Thanks!

Tim
  • 1,583
  • 4
  • 17
  • 34
  • Do you mean manually editing EDMX instead of using the designer? Or XML as storage? Like bdukes says, the latter isn't supported (yet). – Craig Stuntz Mar 03 '09 at 22:31

6 Answers6

44

Entity Framework itself is provider-based, and is designed to operate over a relational database. If you really wanted to, you could write your own provider for EF that reads from/writes to an xml file, but it would be a huge amount of work.

I expect you should really be looking at one of:

  • LINQ-to-XML
  • XML (de)serialization
  • XPath/XQuery
  • XSLT

Entity Framework doesn't have a natural fit in this scenario.

Marc Gravell
  • 976,458
  • 251
  • 2,474
  • 2,830
  • If you really want to pursue a XML database, checkout this project: https://github.com/madskristensen/MiniBlog/blob/master/Website/app_code/code/Storage.cs – NicoJuicy May 20 '14 at 07:45
3

Linq to XML isn't all that much actually. I'd go with a serializable solution instead.

mhenrixon
  • 6,079
  • 4
  • 39
  • 64
2

I like LINQ to XSD: http://linqtoxsd.codeplex.com/

It is basically LINQ to XML with some classes derived from the XSD to ensure it fits the schema...

Kearns
  • 1,059
  • 7
  • 10
  • i've found this tool very useful - however the context menu doesn't seem to show up in vs 2010.. – benpage Aug 05 '10 at 23:20
0
  • Is the problem that you need a file-based data store? If so, you could use a SimpleDB data provider. SimpleDB is great if you need a relational database in a single file. MS Access is great for this as well.

  • XML is designed for communication. If used for storage, it is incredibly inefficient. It might be best to break the two tasks apart and store your data in a relational database and then generate your XML from your data.

  • 1
    The question is about Entity Framework, http://msdn.microsoft.com/en-us/data/ee712907 . Your answer seems to not take that into account. – jpe Aug 26 '13 at 20:38
0

You can use an oledb connection together with a FORXML command... but you will not have all functionality that is available with other providers...

0

I don't think that's really possible.

From MSDN (emphasis mine):

The ADO.NET Entity Framework is designed to enable developers to create data access applications by programming against a conceptual application model instead of programming directly against a relational storage schema.

bdukes
  • 144,904
  • 22
  • 145
  • 175