如果您可以使用任何 .NET DAL 技术,您会选择什么?

发布于 2024-07-12 12:09:57 字数 1179 浏览 6 评论 0原文

几年后,我重新开始 .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:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

有木有妳兜一样 2024-07-19 12:09:57

最初的回应(主要是关于 LINQ 的东西):

  • LINQ to SQL 是你可以在实际项目中使用的东西; 我已经做好了。 我们倾向于将所有数据访问代码放在您右键单击设计图面并选择“查看代码”时生成的分部类中,而不是分散在整个代码中。
  • 使用 LINQ to SQL,如果修改数据库,则需要删除并重新添加表 - 这是一个限制,使用实体框架,您可以“从数据库更新模型”以自动添加/删除这些列。
  • 它可能应该被称为 LINQ to MSSQL Server - 它直接与 SQL Server 绑定。 如果您想对其他数据源使用类似的工具,您可以查看实体框架 - 但目前它还有其他限制 - LINQ to SQL 是它可以工作的概念证明。
  • ADO.NET 数据服务为您提供 ADO.NET 对象的基于 REST 的接口 - 因此您可以调用简单的 Web 服务来检索数据,而无需编写这些服务。
  • 不,没有 LINQ to XML 的设计界面 - 我想有人可以用 XSD 做一些事情,那会很有趣;)
  • 您可以将 Azure 视为“云中的操作系统”,它有一个数据库对于存储,尽管正如您所说,它不是关系型的,没有联接,但您仍然需要查询它的结果。

为了回答你的最后一个问题,我对 NHibernate 或其他人的了解还不够多,但我很乐意使用 LINQ to SQL 进行基本的数据库访问,但我已经开始考虑 LINQ to Entities 来处理更复杂的东西而不是其他的——主要是因为我喜欢那些漂亮的照片。

Initial responses (mostly on the LINQ stuff):

  • LINQ to SQL is something you can use in real projects; I have done. We tended to have all our Data Access code in the partial class that is generated when you right click on the design surface and select "View Code", rather than scattered as one-liners throughout your code.
  • With LINQ to SQL if you modify the database you need to remove and re-add the tables - this is a bit of limitation, with the Entity Framework you can "Update model from database" to auto add/remove these columns.
  • It should probably have been called LINQ to MSSQL Server - it is tied directly to SQL Server. If you want to use similar tooling with other data sources, you could have a look at the Entity Framework - however this currently has other limitations - LINQ to SQL was as much as anything a proof of concept that this could work.
  • ADO.NET Data Services provide you with a REST based interface to your ADO.NET objects - so you can call simple webservices to retrieve data, without having to write those services.
  • No, there isn't a design surface for LINQ to XML - I guess someone could do something with an XSD though, that would be interesting ;)
  • You could think of Azure as "An operating system in the cloud", it has a database for storage, although as you state, it's not relational, there's no joins, but you're still going to be querying it for results.

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.

会发光的星星闪亮亮i 2024-07-19 12:09:57

关于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.

对你的占有欲 2024-07-19 12:09:57

我刚刚必须为我们正在启动的新项目回答同样的问题,并且在比较了我们决定的替代方案后 LLBLGen 因为:

  • 它比实体框架更成熟 它
  • 支持 Linq 查询
  • 它是由几个专门的开发人员积极开发的
  • 它价格便宜
  • 支持很棒

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:

  • It's more mature than Entity Framework
  • It supports Linq queries
  • It's being actively developed by several dedicated developers
  • It's inexpensive
  • The support is just great

ps. I should probably mention that I am not affiliated to llblgen and/or solutions design.

清醇 2024-07-19 12:09:57

我也使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文