2

다음과 같은 열 (ItemNumber, ItemDescription, UPC, Price, Count)이있는 테이블을 반환하는 쿼리 문자열을 사용하여 실행중인 SQL Server 저장 프로 시저가 있습니다. 아이템은 주어진 가격에 있습니다. 따라서 품목 A는 50 개 매장에서 1.00이고 55 개 매장에서는 2.00 개입니다. 여기 Fluent NHibernate 구성 요소 매핑 문제

는 실행 코드 인 가져 오기 :

여기
private IEnumerable<RetailPrice> FetchRetailPrices(IUnitOfWork unitOfWork, string upc) 
{ 
    string StoredProcedure = "EXEC RetailPrices @UPC = :upc"; 
    List<Parameter> parameters = new List<Parameter> 
    { 
     new Parameter("upc", upc) 
    }; 

    return unitOfWork.GetRepository<RetailPrice>().Fetch(
     StoredProcedure, parameters); 
} 

내가 유창함 자 NHibernate를 사용하여 매핑하기 위해 노력하고있어 내 개체 :

namespace Report.Mappings 
{ 
    public class RetailPriceMap : ClassMap<RetailPrice> 
    { 
     public RetailPriceMap() 
     { 
      Id(a => a.Price).Column("Price"); 
      Map(a => a.Count).Column("Count"); 

      Component(a => a.ItemDetails, b => 
      { 
       b.Map(c => c.ItemNumber).Column("ItemNumber"); 
       b.Map(c => c.ItemDescription).Column("ItemDescription"); 
       b.Map(c => c.Upc).Column("UPC"); 
      }); 
     } 
    } 
} 
: 여기
namespace Report.Entities 
{ 
    [Serializable] 
    public class Item 
    { 
     public virtual string Upc { get; protected internal set; } 
     public virtual int ItemNumber { get; protected internal set; } 
     public virtual string ItemDescription { get; protected internal set; } 
    } 
} 

namespace Report.Entities 
{ 
    [Serializable] 
    public class RetailPrice 
    { 
     public virtual Item ItemDetails { get; protected internal set; } 
     public virtual decimal Price { get; protected internal set; } 
     public virtual int Count { get; protected internal set; } 
    } 
} 

내지도입니다

지금은 하나의 가격에 대해 하나의 항목에 대해이 작업을 수행하고 있는데 PropertyNotFoundException이 발생합니다. 'Report.Entities.RetailPrice'클래스의 'ItemNumber'속성에 대한 setter를 찾으십시오.

코드가 Item 객체 대신 RetailPrice 객체에로드하려고하는 이유는 무엇입니까? Fetch 쿼리로 저장 프로 시저를 실행하는 것과 관련이 있습니까?

일단 해결되면 소매점 맵에서 이드의 Item.Upc 부분을 어떻게 만들 수 있습니까?

+0

저장 프로 시저를 사용하지 않고'RetailPrice'을 얻을, 모든 것이 (즉'에 Session.get (...)를'사용) 제대로 작동합니까 나는 비슷한 일을하고 있어요 –

+0

직접 테이블 매핑을 기반으로 잘 작동합니다. –

+0

'Fetch' 메소드는 정확히 무엇을합니까? –

답변

0

완전 매핑을 사용하여 소비자 가격으로 엔티티를 만들었습니다. AliasToBean 변환기는 매핑을 사용하지 않고 관례에 따라 속성에 열을 매핑합니다. 는 addEntity로 변경 변압기 :

public IEnumerable<TEntity> Fetch(String sql,IEnumerable<Parameter> parameters) 
{ 
    return this.BuildQuery(sql, parameters).AddEntity(typeof(TEntity)).List<TEnti‌​ty>(); 
} 
+0

이것이 효과적이었고 Item을 KeyReference로 사용할 수있는 곳으로 가져 오기 위해 Item 클래스에 Map을 추가해야했습니다. –