如果您可以使用任何 .NET DAL 技术,您会选择什么?
几年后,我重新开始 .NET 开发,现在,尤其是使用 LINQ,您访问数据的方式已经发生了变化并且变得更加容易。 例如,在 ASP.NET MVC 网站中,我可以:
- 添加项目
- 添加 LINQ-to-SQL 类
- 将数据库表拖到 LINQ-to-SQL 对象关系设计器上,单击“保存
- 访问权限”并通过 LINQ 单行代码操作我的数据 (我在这里学到的: http://www.asp.net/ learn/mvc/tutorial-11-cs.aspx)
这看起来很棒,但它的真实情况如何?
- 上面的 LINQ-to-SQL 场景是您在实际项目中使用的,还是只是一种快速脚手架技术,即当您开始在数据库中添加、删除字段和表时会发生什么,LINQ-to-SQL 类如何工作保持同步?
我如何理解这个领域的所有新技术,例如
- Subsonic 适合在哪里?
- Astoria(ADO.NET 数据服务)适合哪里?
- NHibernate 适用于哪里?
- 如何将其他数据库与 LINQ-to-SQL 一起使用(我尝试在对象关系设计器上拖动 SQLite 表并收到“不支持的错误”)或者 LINQ-to-SQL 仅适用于 SQL Server
- ?像 LINQ-to-SQL 一样工作,例如,我可以将 XML 文件拖到设计器中,然后使用 LINQ 访问它们,还是需要为此编写自己的代码
LINQ-to-Entities 是否像 LINQ- 一样工作 ? to-SQL ie 自动生成类,但只是有更多选项?
ADO.NET 是否带有其 DataTables?既然我们有了 LINQ,数据集就成了一种旧技术了? LINQ-to-ADO.NET 有意义吗?
Azure 适合你甚至不再拥有 RDBMS 的地方
- 当你的 UI 时,ESB 适合哪里 只是与 WCF 进行 RESTful 对话还是与 Web 服务对话?
既然我们有这么多选择,如果您可以为一个项目选择这些技术中的任何一种,您会选择哪一项,为什么?
I'm getting back into .NET development after a couple years and it seems that now, especially with LINQ, the way you access your data has changed and become much easier. For instance, in a ASP.NET MVC website, I can:
- Add Item
- add LINQ-to-SQL classes
- drag on database tables onto the LINQ-to-SQL Object Relational Designer, click save
- access and manipluate my data via LINQ one-liners
(which I learned here: http://www.asp.net/learn/mvc/tutorial-11-cs.aspx)
This looks great, but how real-world is it?
- is the above LINQ-to-SQL scenario something that you use in real projects or is it just a quick scaffolding technology, i.e. what happens when you start adding, removing fields and tables in your database, how do the LINQ-to-SQL classes stay in sync?
And how do I make sense of all the new technologies in this space, e.g.
- Where does Subsonic fit in?
- Where does Astoria (ADO.NET Data Services) fit in?
- Where does NHibernate fit in?
- How can I use other databases with LINQ-to-SQL (I tried dragging a SQLite table on the Object Relational Designer and got a "not supported error) or is LINQ-to-SQL only for SQL Server?
- does LINQ-to-XML work like LINQ-to-SQL, e.g. can I drag in XML files onto a designer and then access them with LINQ, or do I need to write my own code for this?
does LINQ-to-Entities work like LINQ-to-SQL i.e. automatically generated classes but just with more options?
is ADO.NET with its DataTables and DataSets an old technology now that we have LINQ? Does LINQ-to-ADO.NET make sense?
where does Azure fit in where you don't really even have RDBMS anymore
- where does ESB fit in when your UI is just talking RESTfully to WCF or speaking to web services?
Now that we have so many options, if you could choose any of these technologies for a project, which would you choose and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最初的回应(主要是关于 LINQ 的东西):
为了回答你的最后一个问题,我对 NHibernate 或其他人的了解还不够多,但我很乐意使用 LINQ to SQL 进行基本的数据库访问,但我已经开始考虑 LINQ to Entities 来处理更复杂的东西而不是其他的——主要是因为我喜欢那些漂亮的照片。
Initial responses (mostly on the LINQ stuff):
To answer your final question, I've not learnt enough about NHibernate or others to say, but I'd be happy to use LINQ to SQL for basic database access, but I've started looking at LINQ to Entities for my more complex stuff rather than the others - mostly because I like the pretty pictures.
关于SQLite:我已成功使用dbLinq 构建对SQLite 数据库的LINQ 查询。 它仍处于起步阶段,因此需要修复生成的类中的一些内容,但它满足了我的需求。 我猜它能完成 LinqToSql 能完成的 85% 的事情。 项目中有大量的单元测试来告诉您他们知道什么是失败的。
dbLinq 支持许多其他数据库(MySQL、PostgreSQL、Firebird)。 除了 SQLite 之外我没有用过它。
Regarding SQLite: I've successfully used dbLinq to build LINQ queries to a SQLite database. It's still in it's infancy, so expect to have to fix some stuff in the generated classes, but it worked for my needs. It'll do I'd guess 85% of all the things that LinqToSql will do. And there are plenty of unit tests in the project to tell you what they know is failing.
dbLinq supports many other databases (MySQL, PostgreSQL, Firebird). I've not used it for anything other than SQLite.
我刚刚必须为我们正在启动的新项目回答同样的问题,并且在比较了我们决定的替代方案后 LLBLGen 因为:
ps。 我可能应该提到,我不隶属于 llblgen 和/或解决方案设计。
I've just had to answer the same question for a new project we are starting and after comparison of the alternatives we decided on LLBLGen because:
ps. I should probably mention that I am not affiliated to llblgen and/or solutions design.
我也使用 linq2sql 并且效果很好。
一旦您意识到生成的类是部分类,您就可以在其中放置自定义代码、字段等。
我几乎用生成的 linq2sql 类创建了我的业务类。
需要注意的是:默认情况下 varchar(1) 会转换为 char。 这给我带来了麻烦,因为 varchar(1) 可以是 "" 而 char 不能...但是,在属性窗口中简单切换到字符串就解决了这个问题。
I too use linq2sql and it works great.
Once you realise the generated classes are partials, you can put custom code, fields, whatnot there.
I pretty much made my business classes out of the generated linq2sql classes.
One caveat: a varchar(1) is converted to char by default. This gave me troubles because varchar(1) can be "" whereas char cannot... A simple switch to string in the properties window solved this however.