存储库模式-切换数据库并切换XML文件 [英] Repository pattern - Switch out the database and switch in XML files

查看:71
本文介绍了存储库模式-切换数据库并切换XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储库模式-切换数据库并切换到XML文件.

Repository pattern - Switch out the database and switch in XML files.

你好

我有一个asp.net MVC 2.0项目,并且遵循了Repository模式.

I have an asp.net MVC 2.0 project and I have followed the Repository pattern.

我经常会失去对数据库服务器的访问权限,所以我想采用另一种机制(XML文件)来继续开发.不幸的是,不可能有本地版本的数据库!

Periodically, I am losing access to the database server so I want to have another mechanism in place (XML files) to continue developing. It is not possible to have a local version of the db unfortunately!

我认为使用Repository模式比较容易,以切换出数据库存储库并切换到XML版本. 但是,我在提出解决方案时确实遇到了麻烦.

I thought this would be relatively easy using the Repository pattern, to switch out the db repositories and switch in XML versions. However, I am having real trouble coming up with a solution.

我已经尝试过LinqToXML,但由于LinqToXML ToList返回Generic.List而试图返回新闻列表时遇到了麻烦

I have tried LinqToXML but then ran into problems trying to return a List of News items as the LinqToXML ToList returns Generic.List

我应该手动将XElement列表映射到News列表吗? 与News类上的LinqToSQL属性相比,这似乎有点笨拙,然后只需执行Table ..... ToList();

Should I be mapping the XElement list over to the News list by hand? It just seems a bit clunky compared to LinqToSQL attributes on the News class and then simply doing a Table.....ToList();

任何方向将不胜感激.

谢谢

推荐答案

只需使用Linq-To-XML进行解析.像这样:

Just parse using Linq-To-XML. Something like:

(from a in b
where b.Element("type").Value == "test"
select new c(){d=b.Element("prop").Value}).ToList();

这篇关于存储库模式-切换数据库并切换XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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