具有类自动生成功能的 .NET ORM 解决方案:Subsonic、Castle AR,...? [英] .NET ORM solution with class auto-generation: Subsonic, Castle AR, ...?
问题描述
我曾经使用自定义数据映射库,现在我正在尝试切换到更广泛的 ORM 解决方案.
I used to work with a custom data mapping library, and curently I'm trying to switch to a more widespread ORM solution.
经过一些实验,我将我的要求细化为以下内容:
After some experimentation, I refined my requirements to the following:
- 能够从数据库模式生成可用的类(SQL Server 支持就足够了),
- 支持 ActiveRecord 模式,
- 以编程方式可配置(通过代码或属性,无 HBM 文件),
- 免费.
你能推荐一个吗?
到目前为止我已经尝试过:
So far I have tried:
亚音速 3.0
我目前最喜欢的一个,因为它在功能性和简单性之间取得了很好的平衡.
The one I currently like most, as it feels like a good balance between functionality and simplicity.
我不喜欢什么:
- 对一对多关系的两端使用 IQueryable<> 和复数名称 - 这对我来说似乎很违反直觉;
- 为所有类生成一个文件——比如每个类有一千行,我对代码文件那么大有一种不好的感觉;
T4 处理是自动调用的,因此具有最新架构的数据库必须始终可用.
Castle ActiveRecord
带有 ActiveWriter 插件的 CastleAR 几乎是我所需要的,但 ActiveWriter 的代码并不完美(似乎,不支持 Nullable<> 属性,并且默认的一对多实现不起作用)而且我无法找不到如何手动修复此代码.
CastleAR with ActiveWriter add-in is almost what I need, but ActiveWriter's code isn't perfect (it seems, Nullable<> properties are not supported, and default one-to-many implementation doesn't work) and I couldn't find how to fix this code manually.
Darkside GeneratorStudio 生成更好的代码 - 正确的定义,每个实体一个文件 - 尽管它使用像 RefclassIdRefclass 这样的神秘名称.与独立应用相比,我个人更喜欢 Studio 插件,但这当然是一个小问题.
Darkside GeneratorStudio produces better code - correct definitions, one file per entity - though it uses cryptic names like RefclassIdRefclass. Personally I like Studio addin more than standalone app, but this certainly is a minor issue.
CastleAR 发行版中捆绑了大约 20 个文件;虽然本身不是问题,但感觉像超重.我不需要太多关于 NHibernate 和其他东西的深奥知识吗?
There're about twenty files bundled in the CastleAR distribution; though not a problem by itself, it feels like overweight. Won't I need too much esoteric knowledge about NHibernate and other stuff?
流畅的 NHibernate
广泛推荐,但我找不到代码生成器.
Widely recommended, but I wasn't able to find a code generator for it.
我错过了什么重要的事情吗?
Have I missed something important?
推荐答案
关于你不喜欢 SubSonic 的一些想法:
A few thoughts on the things you don't like about SubSonic:
- 对一对多关系的两端使用 IQueryable<> 和复数名称 - 这似乎对我来说相当违反直觉;
是的,我同意这是非常反直觉的,我从来没有弄清楚为什么会这样,但是您可以很容易地修改模板来解决这个问题.
True, I agree this is very counter intuitive and I've never got to the bottom of why it is that way, but you can pretty easily modify the templates to fix this.
- 为所有类生成一个文件——比如每个类有一千行,我对代码文件那么大有一种不好的感觉;
您可能认为这可能会导致问题,但我还没有遇到任何问题,而且我还没有在 stackoverflow 上看到一个报告.
You'd think this might cause problems but I've yet to come across any and I've yet to see one reported on stackoverflow.
- T4 处理是自动调用的,因此具有最新架构的数据库必须始终可用.
它仅在您编辑 t4 文件时自动调用,因此实际上您只需要在对模板进行更改时可用的最新架构即可.
It's only invoked automatically if you edit the t4 files so really you only need an up-to-date schema available when you're making changes to the templates.
这篇关于具有类自动生成功能的 .NET ORM 解决方案:Subsonic、Castle AR,...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!