2011-12-15 8 views
0

この質問はasked alreadyでしたがまともな答えはありませんでした。代わりにIdを探しているのそれはProductIdために見えるように流暢なnhibernateプロパティ名のためのPrimaryKeyConvention

は流暢NHibernateのためのプロパティ名規則はありますか?

PrimaryKeyConventionは、データベースの列名に適用され、プロパティ名には適用されません。 FluentNHibernate.Visitors.ValidationException

:Idがマッピングされたエンティティ '製品' を持たないで

public class Product 
{ 
    public int ProductId { get; set; } 
    public string Name { get; set; } 
} 

public class AutomappingConfiguration : DefaultAutomappingConfiguration 
{ 
    public override bool ShouldMap(Type type) 
    { 
     bool shouldMap = type.In(typeof(Product)); 
     return shouldMap; 
    } 
} 

public void TestFluentNHibernate() 
{ 
    var configuration = Fluently.Configure(). 
     Database(MsSqlConfiguration.MsSql2008.ConnectionString("database=asd;server=.\\sqlexpress;trusted_connection=true;")) 
     .Mappings(m => 
         { 
          IAutomappingConfiguration cfg = new AutomappingConfiguration(); 
          m.AutoMappings.Add(AutoMap.AssemblyOf<Product>(cfg).Conventions.AddFromAssemblyOf<PrimaryKeyConvention>()); 
         }); 

    var factory = configuration.BuildSessionFactory(); 
} 

結果:

は、このシナリオを考えてみましょう。 IDプロパティをマップするには、Idメソッドを使用します。例:Id(x => x.Id)。

流暢なnhibernateがプロパティ名の「EntityName」+「Id」を探すためにどのような規則を追加/上書きできますか?私はthisの大会のページを見てきましたが、上書きすることはできません。

答えて

1
public class AutomappingConfiguration : DefaultAutomappingConfiguration 
{ 
    public override bool IsId(Member member) 
    { 
     return member.Name == member.DeclaringType.Name + "Id"; 
    } 
} 
関連する問題