我们需要一个 ORM/域建模工具,它允许我们在多个项目/程序集中生成多个相关的域模型,这些模型是通过我们的 MSSQL 数据库以“数据库优先”的方法生成的。我们需要一些帮助来确定哪些工具可以满足我们的需求。
要求是:
-
跨项目关系
- 我们的域被分为许多模块,对于每个客户(我们向其提供源代码),我们不会使用所有模块,因此我们希望“拔掉”他们不需要看到的所有逻辑或访问。
- 例如,我们希望将共享数据(主要是公共查找信息)存储在其自己的公共程序集中。
- 我们不需要模型之间的双向关系(因为这会导致循环引用)。仅生成关系的子端。
我们的域被分为许多模块,对于每个客户(我们向其提供源代码)
-
跨项目继承
- 与上面类似,我们希望能够将通用功能抽象为一个域模型中的基类并继承它们。
- 注意:域之间的继承链接将受到限制,每个子域只能有一个或两个继承链接。
- 注意:这应该不重要,但我们正在使用“每个类型的表”或“类表继承”在关系(DB)模式中建模我们的继承
生成的类将是:
- 用 DataContract/DataMember 属性标记
- 通知属性更改(通过 INotifyPropertyChanged 实现)
- 具有部分 On*PropertyName*Changed() 方法(例如,根据 Linq to SQL 和 Entity Framework 生成的对象)
- (理想,但不是必需)相关集合类型应实现 INotifyCollectionChanged。
任何有关支持(或有解决方法来支持)这些标准的 ORM 工具的反馈,我们将不胜感激!
注意:我们研究过的工具(但这并不完全排除它们):
- LightSpeed (可爱,但不轻易支持跨项目继承)。
- LLBLGen (复杂且包罗万象,但是当使用
AsSeparateProjects
模式进行分组时似乎不支持跨模型关系,更不用说继承了)。
- 实体框架(我刚刚迷路了......设计师的故事 跨多个模型分割域不是很好)。
We're after an ORM/Domain Modelling tool that will allow us to generate several related domain models across multiple projects/assemblies generated in a "database first" approach from our MSSQL database. We need some help working out which tools will meet our needs.
Requirements are:
-
Cross project relationships
- Our domain is split into numerous modules and for each client (whom we give source code to) we don't use all modules and so we'd like to "unplug" all the logic they don't need to see or get access to.
- For example, we want to store a shared data (mostly common lookup information) in it's own common assembly.
- We don't need two-way relationships between models (because that would cause a circular reference). Only the child end of relationship would get generated.
-
Cross project inheritance
- Similar to above, we want to be able to abstract common functionality into base classes in one domain model and inherit them.
- Note: Inheritance links between domains will be limited, only one or two per sub-domain.
- Note: It shouldn't matter, but we are using "Table per Type" or "Class Table Inheritance" to model our inheritance in our relational (DB) schema
-
Generated classes are to be:
- Marked with DataContract/DataMember attributes
- Notify of property changes (via INotifyPropertyChanged implementations)
- Have partial On*PropertyName*Changed() methods (e.g. as per Linq to SQL and Entity Framework generated objects)
- (Ideal, but not necessary) Related collection types should implement INotifyCollectionChanged.
Any feedback as to any ORM tools that support (or have workarounds to support) these criteria would be appreciated!
NOTE: Tools we've looked at (but this doesn't rule them out entirely):
- LightSpeed (lovely, but doesn't support cross project inheritance easily).
- LLBLGen (complicated and all encompassing, but when grouping using
AsSeparateProjects
mode it didn't seem to support cross-model relationships let alone inheritance).
- Entity Framework (I just got lost... The designer story when splitting the domain across multiple models wasn't very nice).
发布评论
评论(2)
这肯定需要小型概念验证项目,因为您的需求不是 EF 论文中常见的描述。
对于 1. 和 2.,请阅读这些文章 (第 1 部分,第 2 部分)并尝试制定简单的解决方案,这将证明您能够同时使用关系和继承在多个 EDMX 之间。
最后一点将通过用于从 EDMX 生成类的自定义 T4 模板来满足 - 从 POCO 模板开始并更改其生成功能。
This definitely needs small Proof-of-concept project because your requirements are not something that is commonly described in papers about EF.
For 1. and 2. go through these articles (part 1, part 2) and try to make simple solution wich will proof that you are able to use both relations and inheritance among multiple EDMXs.
The last point will be satisfied by custom T4 template for generating classes from EDMX - start with POCO template and alter its generation features.
虽然这听起来可能与您要求的相反,但我可能会看看 EF 代码优先。因为它全部构建在 POCO、DbSet 和 DbContext 类之上,所以您将能够非常轻松地让继承工作。
在公共程序集中拥有共享模型和抽象 DbContext。在客户特定的程序集中具有特定的模型和最终的 DbContext。
在WinForms前端,有此处的示例代码了解如何使集合可观察。您需要自己处理 INotifyPropertyChanged,但这非常简单。
EF Code First 对您来说的缺点是无法生成所有类。话虽这么说,它们足够简单,可以在您编写应用程序的其余部分时根据需要编写它们。任何形式的通用自动化工具都很难确定哪些模型和属性属于通用模型和属性,哪些属于特定于客户的模型和属性。
Whilst it might sounds like the reverse of what you're asking for, I'd probably look at EF Code First. Because it's all built on top of POCOs, DbSets and a DbContext class, you'll be able to get the inheritance working pretty easily.
Have your shared models and an abstract DbContext in the common assembly. Have the specific models and final DbContext in the customer specific assemblies.
On the WinForms front, there's example code here for how to make the sets observable. You'll need to take care of INotifyPropertyChanged yourself but that's pretty easy.
The downside of EF Code First for you will be that there's no way to just generate all the classes. That being said, they're simple enough to write that I'd probably just write them on an as-needed basis while you code the rest of the app. Any form of generic, automated tool would have trouble working out which models and properties belong in common vs customer-specific.