C# 带有 XML 文件的实体框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/608477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 10:09:21  来源:igfitidea点击:

Entity Framework with XML Files

c#.netxmlentity-framework

提问by Tim

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.

有人可以指出我使用 XML 文件而不是数据库来解释实体框架的好教程吗?我看过一些很好的 SQL 数据库教程,但我无法跳到 XML 文件。

Thanks!

谢谢!

采纳答案by Marc Gravell

Entity Framework itself is provider-based, and is designedto 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 hugeamount of work.

实体框架本身是基于提供程序的,旨在对关系数据库进行操作。如果你真的想,你可以写你自己的EF从/写入XML文件中读取供应商,但是这将是一个巨大的工作量。

I expect you should really be looking at one of:

我希望你真的应该看看以下之一:

  • LINQ-to-XML
  • XML (de)serialization
  • XPath/XQuery
  • XSLT
  • LINQ 到 XML
  • XML(反)序列化
  • XPath/XQuery
  • XSLT

Entity Framework doesn't have a naturalfit in this scenario.

实体框架没有一个自然在这种情况下适合。

回答by bdukes

I don't think that's really possible.

我不认为这真的可能。

From MSDN(emphasis mine):

来自MSDN(强调我的):

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.

ADO.NET 实体框架旨在使开发人员能够通过针对概念应用程序模型进行编程而不是直接针对关系存储架构进行编程来创建数据访问应用程序。

回答by mhenrixon

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

Linq to XML 实际上并不是那么多。我会改用可序列化的解决方案。

回答by Kearns

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

我喜欢 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...

它基本上是 LINQ to XML 和一些派生自 XSD 的类,以确保它符合架构......

回答by Kearns

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

您可以将 oledb 连接与 FORXML 命令一起使用...但您将无法使用其他提供程序提供的所有功能...

回答by Jason Gray

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

  • 问题是您需要基于文件的数据存储吗?如果是这样,您可以使用 SimpleDB 数据提供程序。如果您需要单个文件中的关系数据库,SimpleDB 非常有用。MS Access 也非常适合这一点。

  • XML 是为通信而设计的。如果用于存储,它的效率非常低。最好将这两个任务分开并将数据存储在关系数据库中,然后从数据生成 XML。