Entity Framework with XML Files [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-t开发者_高级运维opic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
This post was edited and submitted for review 5 months ago and failed to reopen the post:
Improve this questionOriginal close reason(s) were not resolved
Is there a method to use an XML file instead of a database in the Entity Framework?
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.
Linq to XML isn't all that much actually. I'd go with a serializable solution instead.
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...
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.
You can use an oledb connection together with a FORXML command... but you will not have all functionality that is available with other providers...
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.
精彩评论