尖锐的架构忽略了我的公式映射

发布于 2024-11-06 06:57:49 字数 1333 浏览 2 评论 0原文

我遇到一个问题,Sharp Architecture 将正确映射我在 IAutoMappingOverride 类中设置的所有内容(Formula 除外)。这些被简单地忽略,因此当我尝试查询数据库时,我得到了 SQL 的无效标识符

// NUnit setup
public virtual void SetUp()
{
    configuration = NHibernateSession.Init(
        new SimpleSessionStorage(),
        RepositoryTestsHelper.GetMappingAssemblies(),
        new AutoPersistenceModelGenerator().Generate(),
        null,
        null,
        null,
        FluentConfigurer.TestConfigurer.Contracts);

    new FluentConfigurer(configuration)
        .ConfigureNHibernateValidator()
        .ConfigureAuditListeners();
}


public AutoPersistenceModel Generate()
{
    return AutoMap.AssemblyOf<Contrato>(new AutomappingConfiguration())
        .Conventions.Setup(GetConventions())
        .IgnoreBase<Entity>()
        .IgnoreBase(typeof(EntityWithTypedId<>))
        .UseOverridesFromAssemblyOf<EmployeeMap>();
}

// My override.
public class EmployeeMap : IAutoMappingOverride<Employee>
{
    public void Override(AutoMapping<Employee> mapping)
    {
        // This works...
        mapping.Id(x => x.Id, "ID_EMPLOYEE");

        // This is ignored...
        mapping.Map(x => x.Name).Formula("UPPER(LTRIM(RTRIM(FIRST_NAME || ' ' || LAST_NAME)))");
    }
}

有什么想法吗?

I'm having a problem where Sharp Architecture will correctly map everything I have setup in my IAutoMappingOverride classes, except for Formula. These get simply ignored and thus I get SQL's invalid identifier when trying to query the database.

// NUnit setup
public virtual void SetUp()
{
    configuration = NHibernateSession.Init(
        new SimpleSessionStorage(),
        RepositoryTestsHelper.GetMappingAssemblies(),
        new AutoPersistenceModelGenerator().Generate(),
        null,
        null,
        null,
        FluentConfigurer.TestConfigurer.Contracts);

    new FluentConfigurer(configuration)
        .ConfigureNHibernateValidator()
        .ConfigureAuditListeners();
}


public AutoPersistenceModel Generate()
{
    return AutoMap.AssemblyOf<Contrato>(new AutomappingConfiguration())
        .Conventions.Setup(GetConventions())
        .IgnoreBase<Entity>()
        .IgnoreBase(typeof(EntityWithTypedId<>))
        .UseOverridesFromAssemblyOf<EmployeeMap>();
}

// My override.
public class EmployeeMap : IAutoMappingOverride<Employee>
{
    public void Override(AutoMapping<Employee> mapping)
    {
        // This works...
        mapping.Id(x => x.Id, "ID_EMPLOYEE");

        // This is ignored...
        mapping.Map(x => x.Name).Formula("UPPER(LTRIM(RTRIM(FIRST_NAME || ' ' || LAST_NAME)))");
    }
}

Any ideas?

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

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

发布评论

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

评论(2

心凉怎暖 2024-11-13 06:57:49

这不是 Sharp Architecture 的问题,而是 Fluent Nhibernate 的问题。您使用什么版本的 FNH?

This is not an issue with Sharp Architecture, it is an issue with Fluent Nhibernate. What version of FNH are you using?

迷雾森÷林ヴ 2024-11-13 06:57:49

我确认这是 Fluent NHibernate (1.2.0.694) 的问题。以前,列名映射优先于 FluentMappingOverrides,但是
最新的将优先于《公约》。我修改了我的
排除包含公式映射的命名空间的约定
现在好了。

    public class OracleUnderscoredNamingConvention : IPropertyConvention 
    { 
        public void Apply(IPropertyInstance instance) 
        { 
            // Previously worked without this condition. 
            if 
(Utils.WorkableDomainNamespaces.Contains(instance.Property.PropertyType.Nam espace)) 
            { 
instance.Column(OracleConventionSetter.ApplyOracleNamingConventions(instanc e.Property.Name)); 
            } 
        } 
    } 

I confirmed this is an issue with Fluent NHibernate (1.2.0.694). Previously, a column-name mapping would give precedence to the FluentMappingOverrides, but the
latest would give precedence to the Convention. I modified my
convention to exclude the namespaces that contain the formula mappings
and now it's Ok.

    public class OracleUnderscoredNamingConvention : IPropertyConvention 
    { 
        public void Apply(IPropertyInstance instance) 
        { 
            // Previously worked without this condition. 
            if 
(Utils.WorkableDomainNamespaces.Contains(instance.Property.PropertyType.Nam espace)) 
            { 
instance.Column(OracleConventionSetter.ApplyOracleNamingConventions(instanc e.Property.Name)); 
            } 
        } 
    } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文