如何将“linq 转换为 sql” DataContext 写入平面 XML 文件?
我在 Windows 应用程序中使用了 linq to sql,它工作正常,但现在由于某种原因我想删除 sql server 数据库 &相反,我想使用 XML 文件 作为数据存储。 最初
在我的项目中,我做了类似这样的事情。
,我将所有 sql 数据库表拖放到 .net 框架中,在这里我获取我的数据库的 q.dbml 文件我正在访问它,例如
DataContext dc = new qDataContext();
var v = from emp in dc.employees where emp.id == 1 select emp;
是否有任何方法可以用 XML 替换 sql server 数据库,而无需在项目编码中进行更多更改?
I have use linq to sql in my windows application it works fine, but now due to some reason I want to remove that sql server database & instead of it I want to use XML files as data storage. what i have to do without doing much more changes in my C# code.
In my project i have done something like this..
Initially i drop n drag all my sql database table in .net frame work here i get a q.dbml file of my database & i am accessing that like
DataContext dc = new qDataContext();
var v = from emp in dc.employees where emp.id == 1 select emp;
Is there any method to replace that sql server database with XML without doing much more changes in my project coding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你找错了树。
这就是存储库模式的原因;将数据访问层与应用程序逻辑的其余部分分开,以便(例如)通过切换存储库实现可以轻松更改后备存储。
由于您还没有这样做...您只能手动更改代码。 LINQ to SQL 无法“转换”为 LINQ to XML;它只是不会发生。
You are barking up the wrong tree.
This is the reason for the Repository Pattern; separating the data access layer from the rest of the application logic, so that (for example) the backing store can be changed easily, by switching the repository implementation.
Since you have not done that... you are stuck with manually altering your code. LINQ to SQL is not able to be "converted" to LINQ to XML; it just won't happen.
除了为什么您想要这样做...
不。没有任何方法可以从 SQL Server 数据库切换到 XML 文件而不涉及对您的代码进行大量更改。
正如其他人指出的那样,LINQ to SQL 和 LINQ to XML 不是同一件事。 LINQ to SQL 依赖于知道如何连接到数据库、如何读取表等的上下文对象。通用 XML 文件没有等效的概念。至少,您必须重写项目的数据访问部分。
Aside from the why you would want to do this...
No. There is no method of switching from a SQL Server Database to XML files that is not going to involve a lot of changes to your code.
As others have pointed out, LINQ to SQL and LINQ to XML are not the same things. LINQ to SQL relies on a context object that knows how to connect to your database, how to read tables, etc. There is no equivalent concept with generalized XML files. At the very least, you will have to rewrite the data access portion of your project.