C# 对 DevExpress XPO ORM 包有什么想法吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Any thoughts on DevExpress XPO ORM Package?
提问by Ben McNiel
XPOis the object relational mapper of choice at my company. Any thoughts on the pros and cons?
XPO是我公司选择的对象关系映射器。关于利弊的任何想法?
I was just looking for general feeling and anecdotes about the product. We are not switching to XPO. We are just getting rid of hard coded sql strings living in the app and moving completely to ORM for all data access.
我只是在寻找有关该产品的一般感觉和轶事。我们不会切换到 XPO。我们只是摆脱了应用程序中的硬编码 sql 字符串,并完全转向 ORM 以进行所有数据访问。
回答by Nicholas
The pros and cons compared to what? There are a lot of alternatives out there, the most popular being nHibernate, with the new kid 'ADO.NET Entity Framework' on the block.
与什么相比的优缺点?有很多替代方案,最受欢迎的是 nHibernate,其中包含新的“ADO.NET 实体框架”。
Anyways, there are hundreds of answers depending on your situation and requirements.
无论如何,根据您的情况和要求,有数百个答案。
回答by Jeremy McGee
Others will probably pitch in with technical answers (e.g. the query syntax, use of caching, ease or otherwise of mapping to an existing database structure) -- but if you have an established ORM layer the answer is probably
其他人可能会提供技术答案(例如查询语法、缓存的使用、轻松或以其他方式映射到现有数据库结构)——但如果你有一个已建立的 ORM 层,答案可能是
"Why change"?
“为什么要改变”?
I've used XPO successfully for years in an established commercial product with several hundred users. I find that it's fast, flexible and does the job. I don't see any need to change at the moment, as our data volumes aren't particularly large and the foibles (caching, mostly) are things we can work around.
多年来,我在一个拥有数百名用户的成熟商业产品中成功地使用了 XPO。我发现它快速、灵活并且可以胜任。我认为目前没有任何改变的必要,因为我们的数据量并不是特别大,而且我们可以解决的问题(主要是缓存)。
If I were starting afresh I'd definitely look at both NHibernate and the ADO.NET Entity Framework. In practice, though, all are good; I'd most likely look at the commercial situation for the project ahead of the technical questions.
如果我重新开始,我肯定会同时查看 NHibernate 和 ADO.NET 实体框架。然而,在实践中,一切都很好。我很可能会在技术问题之前查看项目的商业情况。
For instance, NHibernate is open-source -- is there a viable community there to support the tool and to provide (if necessary) commercial support?
例如,NHibernate 是开源的——那里是否有一个可行的社区来支持该工具并提供(如有必要)商业支持?
XPO comes from a tools vendor, are they likely to remain in business for the lifetime of the product?
XPO 来自工具供应商,他们是否可能在产品的整个生命周期内继续营业?
ADO.NET Entity Framework comes from Microsoft, who are notorious for changing database technologies more often then Larry fills his fighter with jet fuel -- will this, too, fade away?
ADO.NET Entity Framework 来自微软,后者以更频繁地更改数据库技术而臭名昭著,而不是拉里给他的战斗机加油——这也会消失吗?
回答by Dave Arkell
I like the fact that you can just create classes, and xpo creates the tables and relationships for you - so you can start from a blank database.
我喜欢这样一个事实,即您可以只创建类,而 xpo 会为您创建表和关系 - 因此您可以从一个空白数据库开始。
One issue I don't like is when I want to delete a whole bunch of stuff, it will go through my collection and do a delete on each one. This takes ages, so for this kind of instance, I've had to write some custom sql (delete from table where blah). I'm no expert on XPO, but that's what I found.
我不喜欢的一个问题是,当我想删除一大堆东西时,它会遍历我的收藏并对每个东西进行删除。这需要很长时间,因此对于这种实例,我不得不编写一些自定义 sql(从表中删除等等)。我不是 XPO 方面的专家,但这就是我的发现。
回答by Tomas Pajonk
I second the fact the deleting complex objects with some collections take really, really long. So far the documentation or the forums were not able to help me with this.
我的第二个事实是删除具有某些集合的复杂对象需要非常非常长的时间。到目前为止,文档或论坛无法帮助我解决这个问题。
Apart from that it is really simple to use and gets you going quickly.
除此之外,它使用起来非常简单,可以让您快速上手。
It is also quite hard to figure out your memory usage, I had complex big objects in my design and working with them was a memory hog bigger than I had assumed.
计算你的内存使用情况也很困难,我的设计中有复杂的大对象,使用它们的内存占用比我想象的要大。
回答by Anders Rune Jensen
I have found XPO very frustrating to work with. The main idea of an ORM is to abstract away the underlying data structure. But very quickly you'll notice that they have the default string length hardcoded to 60 chars, so you end up adding these ugly string.unlimited things around every string. So much for abstraction...
我发现使用 XPO 非常令人沮丧。ORM 的主要思想是抽象掉底层数据结构。但是很快您就会注意到它们的默认字符串长度硬编码为 60 个字符,因此您最终会在每个字符串周围添加这些丑陋的 string.unlimited 东西。这么多抽象...
When modelling more complex object you have to use a lot of syntax that really has no place in your object model, like XPCollection. I wanted to store a class which had a dictionary of strings on the class, but sadly XPO was not able to automatically store this into the database.
在对更复杂的对象建模时,您必须使用许多在对象模型中确实没有位置的语法,例如 XPCollection。我想存储一个在类上有字符串字典的类,但遗憾的是 XPO 无法自动将其存储到数据库中。
So while it works ok for simple types, it very quickly breaks down when you want to store more complex things. That combined with their mediocre support really leaves a LOT to be desired.
因此,虽然它适用于简单类型,但当你想要存储更复杂的东西时,它很快就会崩溃。再加上他们平庸的支持,确实有很多不足之处。
回答by Przemaas
XPO in overall is easy to work with. However, it can be a little pain when you plan to work with legacy database or try to introduce it into a brownfield app. Most painful obstacles I hit were:
总体而言,XPO 易于使用。但是,当您计划使用旧数据库或尝试将其引入棕地应用程序时,可能会有点痛苦。我遇到的最痛苦的障碍是:
- all objects need to inherit from XPO related classes and/or use XPO related attributes. So, no POCO objects
- no support for readonly persistent fields OOTB. It's possible, but you need to do a little hacking to stop XPO from updating field in DB
- no support for pre filtering associations, which can cause excessive network load
- Poor support for foreign composite keys. To be fair, no ORM handles composite keys nicely. They are considered to be "anti-ORM" pattern.
- few small annoyances
- 所有对象都需要从 XPO 相关类继承和/或使用 XPO 相关属性。所以,没有 POCO 对象
- 不支持只读持久字段 OOTB。这是可能的,但你需要做一些黑客来阻止 XPO 更新数据库中的字段
- 不支持预过滤关联,会导致网络负载过大
- 对外复合键的支持不佳。公平地说,没有 ORM 能很好地处理复合键。它们被认为是“反 ORM”模式。
- 一些小烦恼
As Dennis pointed out in comments, XPO was greatly improved since I wrote this answer originally. In particular, below things are no longer an issue:
正如丹尼斯在评论中指出的那样,自从我最初写这个答案以来,XPO 得到了很大的改进。特别是,以下事情不再是问题:
- no serialization, so XPO objects are hard to use in disconected win forms scenario, with data coming through web services. - XPO supports now various serialization scenarios and can be easily used with WCF.
- you cannot do many-to-many relation mapping with your own interim table. Xpo wants specific name for such interim tables. - This is no longer a case
- no support for enums in postgreSql provider - You just need to write really simple value converter and you are good.
- 没有序列化,因此 XPO 对象很难在断开连接的 Win Forms 场景中使用,数据来自 Web 服务。- XPO 现在支持各种序列化方案,并且可以轻松地与 WCF 一起使用。
- 您不能使用自己的临时表进行多对多关系映射。Xpo 需要此类临时表的特定名称。- 这不再是一个案例
- postgreSql 提供程序中不支持枚举 - 您只需要编写非常简单的值转换器就可以了。
Also, below issues will no longer be problem with next XPO release, coming later this year:
此外,以下问题在今年晚些时候发布的下一个 XPO 版本中将不再是问题:
- no support for keys of type long
- no support for db schema in postrgeSql provider
- 不支持 long 类型的键
- postrgeSql 提供程序中不支持数据库架构
All in all, XPO was greatly improved. Most painfull obstacles were removed. You can still hit problems while working with legacy DB. But in general XPO became quite convenient to use.
总而言之,XPO得到了很大的改进。大多数痛苦的障碍都被移除了。在使用旧数据库时,您仍然可能会遇到问题。但总的来说,XPO 变得非常方便使用。
回答by Steven Evers
I've been working with it for 6-7 months now and the seller for me was the fact that all of their UI components work relatively seamlessly with XPO - and their UI components are top notch.
我已经使用它 6-7 个月了,对我来说,卖家认为他们所有的 UI 组件都与 XPO 相对无缝地工作——而且他们的 UI 组件是一流的。
Some might note that their forums are poorly monitored and have little useful traffic - this is true. The secret is to fill out tickets though. They respond quickly, and accurately to all of their support tickets.
有些人可能会注意到他们的论坛监控不力,有用的流量很少——这是真的。秘诀是填写门票。他们快速、准确地响应所有支持请求。
回答by Roman Eremin
This is all you need to do to start writing your domain objects (try do the same in other systems):
这就是开始编写域对象所需要做的一切(尝试在其他系统中执行相同的操作):
using System;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using NUnit.Framework;
namespace XpoTdd {
public class Person:XPObject {
public Person(Session session) : base(session) { }
public string FirstName { get; set; }
public string LastName { get; set; }
[Persistent]
public string FullName { get { return FirstName + " " + LastName; } }
}
[TestFixture]
public class PersonTests {
[Test]
public void TestPersistence() {
const string connStr = "Integrated Security=SSPI;Pooling=false;Data Source=(local);Initial Catalog=XpoTddTest";
UnitOfWork session1 = new UnitOfWork();
session1.ConnectionString = connStr;
Person me = new Person(session1);
me.FirstName = "Roman";
me.LastName = "Eremin";
session1.CommitChanges();
UnitOfWork session2 = new UnitOfWork();
session2.ConnectionString = connStr;
me = session2.FindObject<Person>(CriteriaOperator.Parse("FullName = 'Roman Eremin'"));
Assert.AreEqual("Roman Eremin", me.FullName);
}
}
}