ORM 有何伟大之处?
所以我的头靠在墙上,希望有人能来帮忙,要么把墙移走,要么阻止我的头移动!
在过去的 3/4 周中,我一直在调查 ORM 是否为新项目做好了准备。 ORM 必须映射到现有的大型且老化的 SQL 数据库。
所以我尝试了亚音速。我真的很喜欢 v2 和 v3,经过修改后可以与 VB 很好地配合,并且 SQL 中的命名模式运行正常。然而,它缺乏单独的实体属性名称与列名称的灵活性,这让我抓狂(对不起,罗布)。
我尝试过实体框架,但我发现它和其他框架一样在某些方面有所欠缺。
所以我硬着头皮尝试了 nHibernate,但大约一周后,它按照我喜欢的方式工作(在 Codesmith 的帮助下为我生成类/hbms),我对启动所需的时间感到沮丧(构建一个配置对象) ,尽管尝试了一些技巧来减少这个时间。
我本质上是在构建一个可以在应用程序和网站之间共享的 DAL 类之后。我是不是找错了树?对于具有 100 个表的遗留项目,我应该返回 ado.net 并使用 DTO 吗?啊啊!
很抱歉问题的粗鲁风格。我的头发不多了,我想保留我拥有的!!
预先感谢,埃德
PS。我应该补充一点,我非常了解 SQL,并且不害怕自己动手编写快速查询。如果有的话我不需要对 SQL 隐藏
So I'm having a head against the wall moment and hoping somebody can come help either remove the wall or stop my head from moving!!
Over the last 3/4 weeks I've been investigating ORM's in readyness for a new project. The ORM must map to an existing, large and ageing SQL database.
So I tried Subsonic. I really liked v2 and v3 after modding to work nicely with VB and named schemas in SQL was running OK. However, its lack of flexibility of having separate entity properties names vs column names had me pulling my hair out (sorry Rob).
I tried Entity Framework but I found like others it lacking in certain areas.
So I bit the bullet and tried nHibernate but after a week or so getting it working how I liked (with help from Codesmith to generate classes/hbms for me) I'm frustrated with the time it takes to startup (build a config object), despite trying a number of tricks to reduce this time.
I'm essentially after building a DAL class that I can share between apps and websites. Am I barking up the wrong tree? For a legacy project with 100s of tables should I go back to ado.net and use DTOs? Aarrgh!
Sorry for the ranty style of question. I don't have much hair left and I'd like to keep what I have!!
Thanks in advance, Ed
PS. I should add that I know SQL very well and not scared of getting my hands dirty to write fast queries. If anything I don't need to be hid from SQL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ORM 让您:
如果您不使用 ORM,则以上所有内容都必须手动处理。
PS:我同意 Dmitry 关于 NHibernate 启动时间的看法(参见问题评论)。另外,你尝试过Fluent NHibernate吗? Fluent NHibernate 非常简单。当我第一次映射数据库时,我简直不敢相信自己的眼睛。它甚至比 DevExpress XPO 等专有 ORM 更容易。
ORM let's you:
All of the above would have to be handled by hand if you werent using ORM.
PS: I agree to Dmitry as to the startup time of NHibernate (see question comments). Besides, did you try Fluent NHibernate? Fluent NHibernate is impressively easy. I couldn't believe my eyes when I first mapped a database. It's even easier than proprietary ORMs like DevExpress XPO.
ORM 工具的最大好处是它可以帮助您正确地对应用程序进行分层。现在大多数项目都使用数据层来连接到数据库。您从 ORM 工具开始生成与数据库对象相对应的类。然后使用这些方法定义一个接口。所有持久性代码都使用此接口的方法。这样,业务逻辑层只耦合到这个更高层的接口,并且不需要了解数据库。事实上,不应该依赖 ADO.NET 甚至 NHibernate。
ORM 工具的另一个优点是您可以将应用程序与数据库服务器分离。您可以更改数据库引擎并仍然使用相同的代码。此外,ORM 向您隐藏的不仅仅是 SQL 的复杂性。它还可以帮助您处理事务逻辑和连接池。
我想说,对于新项目来说,ORM 工具是必要的。对于遗留项目来说,这并没有多大好处,除非您有时间/金钱从头开始。
The biggest benefit of an ORM tool is that it will help you layer your application correctly. Most project nowadays use a Data Layer to connect to the database. You start from the ORM tool to produce classes that correspond to your database objects. Then you define an interface using these methods. All persistence code uses the methods of this interface. This way the business logic layer is only coupled to this higher-layer interface and needs to know nothing about the database. In fact there should be no dependency on ADO.NET or even NHibernate.
Another advantage of ORM tools is that you de-couple your application from the database server. You could change the db engine and still use the same code. Also there isn't only the complexity of the SQL that the ORM hides from you. It can also help you with transactions logic and connection pooling.
I'd say that for new projects an ORM tool is a necessity. For legacy projects it isn't so much beneficial, unless of course you have the time/money to start from scratch.
根据我的经验,大多数 ORM 最终都比 SQL 复杂得多。这违背了使用它们的全部目的。
我热衷的一种解决方案是 LINQ2SQL。它非常适合作为存储过程或视图的薄层。它真的很容易使用,并且不会试图隐藏 SQL。
In my experience, most ORMs end up being way more complex than SQL. Which defeats the entire purpose of using them.
One solution I'm enthusiastic about is LINQ2SQL. It excels as a thin layer about stored procedures or views. It's really easy to use and doesn't try to hide SQL.
这里基本上有两个问题:
ORM 有什么好处? Stackoverflow 上也有类似的问题。请参阅:
我可以缩短 NHibernate 的启动时间吗?请参阅:
There are basically two questions here:
What's great about ORMs? There are similar questions on Stackoverflow. See:
How can I improve NHibernate startup time? See: