FluentNHibernate - 映射时获取实体名称。当前方法已过时

发布于 2024-11-14 05:18:45 字数 1546 浏览 1 评论 0原文

我目前正在使用 AutoMappingOverride 自动命名我的表,并将表的名称设置为实体的复数名称,如下所示。

public class PersonMappingOverride : IAutoMappingOverride<Person>
    {
        public void Override(AutoMapping<Person> mapping)
        {
            mapping.Table(mapping.EntityType.Name.Pluralize());
            mapping.Id(x => x.PersonId).Column("PersonId").GeneratedBy.Increment();
            mapping.Map(x => x.Name).CustomSqlType("nvarchar(200)");
        }
    }



  public static string Pluralize(this string input)
        {
            return System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new CultureInfo("en-US")).Pluralize(input);
        }

我收到以下错误。

'FluentNHibernate.Mapping.ClasslikeMapBase.EntityType' 已过时:'不要调用此方法。实施细节被错误地公开。将在下一个版本中设为私有。

有谁知道获取实体名称的正确方法?我已经做了相当多的谷歌搜索,只找到了人们使用这种过时的方法来实现我需要的东西的例子。

干杯

史蒂夫,

感谢所有提供帮助的人。对于我的用例来说,使用约定比覆盖更优雅。

var sqlConfig = MsSqlConfiguration.MsSql2005.ConnectionString(ConnectionString);
            var config = Fluently.Configure().Database(sqlConfig);
            config.Mappings(c => c.AutoMappings.Add(AutoMap.AssemblyOf<User>(new IJAutomappingConfiguration()).Conventions.AddFromAssemblyOf<TableNamingConvention>())); 




  public class TableNamingConvention : IClassConvention
    {
        public void Apply(IClassInstance instance)
        {
            instance.Table(instance.EntityType.Name.Pluralize());
        }
    }

这是使其正常工作的完整代码。

I am currently automatically naming my tables in fluent NHibernate by using AutoMappingOverride's and setting the name of the table to the pluralised name of the entity like so.

public class PersonMappingOverride : IAutoMappingOverride<Person>
    {
        public void Override(AutoMapping<Person> mapping)
        {
            mapping.Table(mapping.EntityType.Name.Pluralize());
            mapping.Id(x => x.PersonId).Column("PersonId").GeneratedBy.Increment();
            mapping.Map(x => x.Name).CustomSqlType("nvarchar(200)");
        }
    }



  public static string Pluralize(this string input)
        {
            return System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new CultureInfo("en-US")).Pluralize(input);
        }

I am getting the following error.

'FluentNHibernate.Mapping.ClasslikeMapBase.EntityType' is obsolete: 'Do not call this method. Implementation detail mistakenly made public. Will be made private in next version.'

Does anyone know the correct way of getting the entity name? I've done a fair bit of Googling and have only found examples of people using this obsolete method to achieve what I need.

Cheers

Steve

Thanks for all the great help guys. Using conventions is way more elegant for my use case than the overrides anyway.

var sqlConfig = MsSqlConfiguration.MsSql2005.ConnectionString(ConnectionString);
            var config = Fluently.Configure().Database(sqlConfig);
            config.Mappings(c => c.AutoMappings.Add(AutoMap.AssemblyOf<User>(new IJAutomappingConfiguration()).Conventions.AddFromAssemblyOf<TableNamingConvention>())); 




  public class TableNamingConvention : IClassConvention
    {
        public void Apply(IClassInstance instance)
        {
            instance.Table(instance.EntityType.Name.Pluralize());
        }
    }

Here is the full code to get this working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

野稚 2024-11-21 05:18:45

以下是使用约定的方法:

public class NamingConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        instance.Table(instance.EntityType.Name.Pluralize());
    }
}

Here's how you would do it using a Convention:

public class NamingConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        instance.Table(instance.EntityType.Name.Pluralize());
    }
}
酒几许 2024-11-21 05:18:45

也许尝试一下约定,FluentNHibernate 约定

Maybe trying Conventions, FluentNHibernate Conventions

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