2011-05-09 61 views
1

我遇到問題,夏普體系結構將正確映射我在IAutoMappingOverride類中設置的所有內容,但Formula除外。這些被簡單地忽略,因此當試圖查詢數據庫時,我得到SQL的invalid identifier夏普體系結構忽略我的公式映射

// 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)))"); 
    } 
} 

任何想法?

回答

0

我確認這是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)); 
      } 
     } 
    } 
0

這不是夏普架構的問題,它是Fluent Nhibernate的問題。你使用的是什麼版本的FNH?