How to use / display the database view to populate the contained collection?

I have the following classes:

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; }
}

I have a database view that aggregates Itemsby location and some other filtering. I would like to refer to this view in the mapping to populate the collection FloorFill.BackstockLocations.

What approach should be used to populate this collection? I would like the collection to be lazy, but for now I’ll just be happy to receive the data.

Here are the mapping files:

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();
    }
}

Summary request:

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_
+5
source share
1 answer

The view display is the same as the table display if you are not trying to update it.

?

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

"LocationId" - , WithColumns .

, .

+4

All Articles