2012-03-13 9 views
0

リフェラルには多くのリードがあります。しかしながら、エンティティはエージェント識別子によって関連づけられる。リファラルエンティティ内では、マッピングが正しく機能するように、agent_idカラムにマッピングされた整数プロパティを追加する必要がありました。オブジェクトのFluent-Nhibernate HasManyプロパティリファレンス

私はエンティティからAGENTIDプロパティを削除し、そのように「エージェント」オブジェクトのマッピングを行う場合:

HasMany(x => x.Leads) 
     .AsBag() 
     .KeyColumn("Agent_Id") 
     .PropertyRef("Agent"); 

私はエラーに遭遇:

Object does not match target type.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.TargetException: Object does not match target type.

私は推測する、私はこれが容認できる解決策であるかどうか尋ねていますか?追加のAgentIDプロパティーは、プロパティー参照内以外では使用されません。現時点では変更できないドメインモデルを変更する必要があるため、このマッピングを実行する別の方法がありますか?

作業マッピング

public class Referral 
{ 
    public virtual int Id { get; set; } 
    public virtual int AgentID { get; set; } 
    public virtual Agent Agent { get; set; } 
    public virtual int? PositionNumber { get; set; } 
    public virtual DateTime? LastReferralDate { get; set; } 
    public virtual Account Account { get; set; } 

    public virtual IEnumerable<Lead> Leads { get; set; } 
} 

public ReferralMap() 
{ 
    Table("Referral"); 
    LazyLoad(); 
    Id(x => x.Id).GeneratedBy.Identity().Column("Id"); 
    Map(x => x.PositionNumber).Column("PositionNumber"); 
    Map(x => x.LastReferralDate).Column("LastReferralDate"); 
    Map(x => x.AgentID).Column("Agent_ID"); 
    References(x => x.Agent).Column("Agent_ID"); 
    References(x => x.Account).Column("Account_id"); 

    HasMany(x => x.Leads) 
     .AsBag() 
     .KeyColumn("Agent_Id") 
     .PropertyRef("AgentID"); 

} 

答えて

1

私はあなたの代わりに

public LeadMap() 
{ 
    CompositeId().KeyReference(l => l.Agent, "Agent_Id"); 
} 
+0

おかげフィ​​ーロの

public LeadMap() { Id(l => l.AgentId).Column("Agent_Id"); } 

を持っているので、これは問題にそれはなかった一方で、それは、あると思います正しい方向に私を指摘した。要求されなかったものに結合を指定するのではなく、数式マッピング( "(l.Agent_id = Agent_ID)のリードから数を選択(*))を使用する方が簡単だったことが判明しました。 – Jesse

関連する問題