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_
WithColumns ("Id")를 삭제했습니다. select 문은 InventoryLocations.ItemRefence를 FloorFill.Id와 비교하고이를 FloorFill.ItemRefence에 매핑해야합니다. – Barry
다른 엔티티의 맵에서 결정할 수있는 WithTableName이 없어야합니다. InventoryLocationMap에서 ID의 ColumnName을 기본 키로 제거해야하며 외래 키를 속성으로 매핑하기 때문에 Map (x => x.ItemReference)을 제거해야합니다. 이제 어떻게됩니까? –
제안 된 변경 사항에 대한 이해를 반영하여 코드 목록을 편집했습니다. 이것은 Backstock 위치 수집을 생성하지 않습니다. – Barry