在web api.2中使用XML文件作为数据库? [英] Using XML file as database in web api.2?

查看:66
本文介绍了在web api.2中使用XML文件作为数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在C#中创建一个Web API来搜索存储在xml文件中的书名/标题作为数据库。问题是我可以直接在Visual Studio中使用xml文件而不使用EF吗?

感谢您的帮助!



我尝试了什么:



我已经在App-Data中导入了xml文件并希望将其用作数据库,首先我做了一个控制器与使用实体框架的操作但我不确定我是否需要这种类型的控制器,因为我想使用xml文件。

I'm trying to make a Web API in C# to search through book names/titels which store in xml file as the database. The question is can I use the xml file directly in Visual studio without using EF and how?
Thanks for any help!

What I have tried:

I've imported the xml file in App-Data and want to use it as database,first I made a "controller with actions using Entity Framework" but I'm not sure if I need this type of controller since I want to use xml file.

推荐答案

是的,你可以使用作为数据源,但是你需要在很大程度上依赖于XML序列化器和反序列化器,你必须编写每个函数,每个代码来存储,访问,修改和删除数据。另外,对于约束的情况(例如主键,外键等),您必须自己管理所有内容。



我不确定EF是否可以升级为运行XML,我也没有听到有人这样做过。所以你在这里留下自己的代码,没有人会帮助你。无论如何,如果你想考虑JSON而不是XML,我可以提供我自己的文章,其中我解释了有关JSON的基础知识以及如何编写应用程序以使用JSON作为数据源,使用C#在JSON中从零到英雄 [ ^ ]。



开始阅读有关使用XML标准序列化数据的好方法的长文档,在MSDN上, XML和SOAP序列化 [ ^ ]。

c# - 带有XML文件的实体框架 - 堆栈溢出 [ ^ ]
Yes, you can use that as the data source but for that you will need to heavily depend on the XML serializers and deserializers and you will have to write every function, every code to store, access, modify and delete the data. Plus, for the cases of constraints (such as primary keys, foriegn keys etc.) you will have to manage everything yourself.

I am not sure if EF can be elevated to run on XML, and I haven't heard anyone do this either. So you are left with your own code here and none will help you. Anyways, if you want to consider JSON instead of XML, I can provide you my own article, in which I explain the basics about JSON and how to program the application to use JSON as the data source, From zero to hero in JSON with C#[^].

Get started reading a long documentation about good ways to serialize the data using XML standard, here on MSDN, XML and SOAP Serialization[^].
c# - Entity Framework with XML Files - Stack Overflow[^]


这篇关于在web api.2中使用XML文件作为数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆