什么将是一个很好的approch使用XML作为数据持久的小C#应用程序? [英] What would be a good approch for using XML as data persistence for a small C# app?
问题描述
我需要什么将是一个很好approch使用XML作为数据持久的小C#应用程序的一些意见。这是一个独立的应用程序,用户不共享相同的数据持久性的,因此,文件访问是排他性的。这就是为什么我首先想到的XML。
I need some opinions on what would be a good approch for using XML as data persistence for a small C# app. This is a stand alone app, users do not share the same data persistence, hence, file access is exclusive. This is why I thought of XML in the first place.
我知道我的设计模式,因此,如果我写的惯常层,我可以分离的持久性,然后在需要时以后改变它。话又说回来,这是一个小的应用程序,所以我需要快速的写。
I know my design patterns, so if I write the usual layers, I can isolate the persistence and then change it afterwards, if needed. Then again, it's a small app, so I need to write it fast.
我应该只使用LINQ到XML和克服呢?如果是这样,这将是我的改写工作,如果我决定了嵌入式数据库取代XML?怎么样的Linq性能写入XML文件?
Should I just use Linq to XML and get over with it? If so, what would be my rewriting efforts if I decide to replace XML with a embedded database? How's Linq performance in writing into the XML file?
但是,如果我不使用LINQ去,你会怎么家伙建议?
But if I don't go with Linq, what would you guys suggest?
更新
通过我的评论,我可能需要指定多一点。这是一份成绩单的应用程序供教师使用。这是我的主要实体:
By the comments I got, I might need to specify a little more. This is a report card app for teacher use. These are my main entities:
- 学生
- 课程
- 教师(应该只有一个,但我会保存,因为未来整合可能性吧)
- 年级(学生可以在每门课程不止一个档次)
现在的一些问题:
- 在引擎盖,我应该有每个实体中的一个XML文件?
- 在引擎盖,我应该使用LINQ到XML?有没有别的东西,甚至被认为是?
和一些评论
- 在我知道我应该与持久化类的实例使用接口
的IEnumerable< myEntity所>
,应在输入和输出。这给了我的灵活性。 - 虽然我给的建议真的很开放,我真的不想考虑,现在嵌入数据库。这个小应用程序是一个令人兴奋的机会去工作,用新的东西试验生产(不仅是测试)和低风险。
- I understand that I should interface with the "persistence class instance" using
IEnumerable<MyEntity>
, on either inputs and outputs. That gives me flexibility. - Although I'm really open to suggestions, I really do not want to consider embedding a database right now. This small app is an exciting opportunity to get to work and experiment with new things on production (not only testing) and little risk.
推荐答案
我建议你:
- 定义模式(一级)重新presenting需要被存储的数据(可分层)
- 使用的序列化序列化或反序列化到XML或二进制甚至JSON如果需要的话。
- Define a model (one class) representing the data that needs to be stored (can be hierarchial)
- Use serialization to serialize or deserialize to XML or binary or even JSON if needed.
这篇关于什么将是一个很好的approch使用XML作为数据持久的小C#应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!