在 SharpArchitechture 项目中在哪里创建映射文件

发布于 2024-09-30 10:28:33 字数 138 浏览 2 评论 0原文

我正在关注 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2024-10-07 10:28:33

SharpArchitecture 使用 FluentNHibernate 根据项目 PROJECT.Core 中定义的实体自动创建 NHibernate 映射。它将基于领域模型定义关系。您会发现经常需要自定义映射。

您将在项目 PROJECT.Data 中执行对默认映射的覆盖。在此项目中,您将找到一个名为 NHibernateMaps 的文件夹,其中包含几个用于设置默认映射策略的类。第 1 步是评估默认映射策略,看看是否需要对默认策略进行系统范围的更改。其次,您可能想要覆盖特定实体的映射。为此,创建一个名为 [EntityClass]Map 的新类,如下所示:

public class EntityMap : IAutoMappingOverride<Entity> {

  public void Override(AutoMapping<Entity> mapping) {
    //use the mapping. to override default mappings. Here is just an example
    mapping.References(x => x.EntityCategory).Fetch.Join();
    mapping.References(x => x.EntitySubItem).NotFound.Ignore();
  }
}

您的应用程序将这一切与 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:

public class EntityMap : IAutoMappingOverride<Entity> {

  public void Override(AutoMapping<Entity> mapping) {
    //use the mapping. to override default mappings. Here is just an example
    mapping.References(x => x.EntityCategory).Fetch.Join();
    mapping.References(x => x.EntitySubItem).NotFound.Ignore();
  }
}

Your application ties this all up in the InitializeNHibernateSession method within the global.asax.cs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文