在 SharpArchitechture 项目中在哪里创建映射文件
我正在关注 Sharparchitecture.net 上的教程。我已经使用 T4 创建了一些实体,但我无法弄清楚到数据库的映射是在哪里完成的?
我想在映射文件中创建一些关系,但是我应该添加一个新的映射文件还是已经使用 T4 创建了一个映射文件?
I am following the tutorial on sharparchitecture.net. I have created a few entities using T4, but I can't figure out where the mapping to the database is done?
I would like to create some relations in the mapping files, but should I add a new mapping file or are there already created one with T4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SharpArchitecture 使用 FluentNHibernate 根据项目 PROJECT.Core 中定义的实体自动创建 NHibernate 映射。它将基于领域模型定义关系。您会发现经常需要自定义映射。
您将在项目 PROJECT.Data 中执行对默认映射的覆盖。在此项目中,您将找到一个名为 NHibernateMaps 的文件夹,其中包含几个用于设置默认映射策略的类。第 1 步是评估默认映射策略,看看是否需要对默认策略进行系统范围的更改。其次,您可能想要覆盖特定实体的映射。为此,创建一个名为 [EntityClass]Map 的新类,如下所示:
您的应用程序将这一切与 global.asax.cs 中的 InitializeNHibernateSession 方法联系起来。
SharpArchitecture uses FluentNHibernate to automagically create NHibernate mappings based on your Entities as defined in project PROJECT.Core. It will define relationships based on the domain model. You will find that you frequently need to customize your mappings.
The project PROJECT.Data is where you will perform overrides to the default mapping. In this project you will find a folder called NHibernateMaps with several classes to setup the default mapping strategy. Step 1 would be to evaluate the default mapping strategy to see if you need to make any systemwide changes to the default strategies. Second, you may want to override a mapping for an specific entity. To do this create a new class called [EntityClass]Map that looks like the following:
Your application ties this all up in the InitializeNHibernateSession method within the global.asax.cs.