2009-07-10 2 views
5

다음 클래스가 있습니다.포함 된 컬렉션을 채우기 위해 데이터베이스 뷰를 사용/매핑하는 방법?

public class FloorFill 
{ 
    protected FloorFill(){} 
    public virtual ProductCatalog Catalog { get; set; } 
    public virtual Inventory BatchedItem { get; set; } 
    public virtual Transaction Batch { get; set; } 
    public virtual int ItemReference { get; set; } 
    public virtual IList<InventoryLocation> BackstockLocations { get; set; } 
} 
public class InventoryLocation 
{ 
    public InventoryLocation(){} 
    public virtual int Id { get; set; } 
    public virtual int ItemReference { get; private set; } 
    public virtual Location Where { get; set; } 
    public virtual int HowMany { get; set; } 
} 

위치 별 Items 및 기타 필터링을 집계하는 데이터베이스 뷰가 있습니다. FloorFill.BackstockLocations 컬렉션을 채우기 위해 매핑에서이 뷰를 참조하고 싶습니다.

이 컬렉션을 채우기 위해 어떤 방법을 사용해야합니까? 게으름에 대한 컬렉션을 원하지만이 시점에서 데이터를 얻으려면 기꺼이 기다려야합니다.

다음은 매핑 파일입니다.

public class FloorFillMap : EntityBaseMap<FloorFill> 
{   
    public FloorFillMap() 
    { 
     Map(x => x.ItemReference); 
     References(x => x.Catalog, "ProductCatalogId") 
         .WithForeignKey(); 
     References(x => x.Batch, "TransactionId") 
       .WithForeignKey() 
       .Cascade.SaveUpdate(); 
     References(x => x.BatchedItem, "InventoryId") 
       .WithForeignKey() 
       .Cascade.SaveUpdate(); 
     HasMany(x => x.BackstockLocations) 
      .KeyColumnNames.Add("ItemReference") 
      .Inverse() 
      .Cascade.None() 
      .LazyLoad(); 
    } 
} 

public class InventoryLocationMap : ClassMap<InventoryLocation> 
{ 
    public InventoryLocationMap() 
    { 
     WithTable("InventoryLocations"); 
     Id(x => x.Id); 
     References(x => x.Where, "LocationId") 
      .FetchType.Join() 
      .Cascade.None(); 
     Map(x => x.HowMany); 
     ReadOnly(); 
    } 
} 

결과 쿼리는 다음과 같습니다.

SELECT 
    this_.Id as Id33_0_, 
    this_.Created as Created33_0_, 
    this_.ItemReference as ItemRefe3_33_0_, 
    this_.Modified as Modified33_0_, 
    this_.RowVersion as RowVersion33_0_, 
    this_.ProductCatalogId as ProductC6_33_0_, 
    this_.TransactionId as Transact7_33_0_, 
    this_.InventoryId as Inventor8_33_0_ 
FROM [FloorFill] this_ 

답변

4

만큼 업데이트하려고하지 않는 한, 테이블 매핑과 동일 여기

은 매핑 파일입니다 그것.

이 진술에서 무엇을하려고합니까?

References(x => x.Where, "LocationId") 
    .FetchType.Join().WithColumns("Id").Cascade.None(); 

"LocationId" 키 열 이름이지만, WithColumns 호출은 그 값을 덮어 쓰게됩니다.

무슨 일이 일어나고 있는지 또는 어떤 일이 일어나지 않았는지에 대한 다른 표시가 도움이 될 것입니다.

+0

WithColumns ("Id")를 삭제했습니다. select 문은 InventoryLocations.ItemRefence를 FloorFill.Id와 비교하고이를 FloorFill.ItemRefence에 매핑해야합니다. – Barry

+0

다른 엔티티의 맵에서 결정할 수있는 WithTableName이 없어야합니다. InventoryLocationMap에서 ID의 ColumnName을 기본 키로 제거해야하며 외래 키를 속성으로 매핑하기 때문에 Map (x => x.ItemReference)을 제거해야합니다. 이제 어떻게됩니까? –

+0

제안 된 변경 사항에 대한 이해를 반영하여 코드 목록을 편집했습니다. 이것은 Backstock 위치 수집을 생성하지 않습니다. – Barry