gpt4 book ai didi

c# - 如何使用/映射数据库 View 来填充包含的集合?

转载 作者:太空狗 更新时间:2023-10-29 23:27:54 25 4
gpt4 key购买 nike

我有这些类(class):

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

我有一个数据库 View ,它按位置和一些其他过滤聚合 Items。我想在映射中引用此 View 以填充 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_

最佳答案

映射 View 与映射表相同,只要您不尝试更新它即可。

你想在这个声明中做什么?

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

"LocationId" 是键列名称,但 WithColumns 调用将覆盖该值。

错误或其他指示正在发生或未发生的事情会有所帮助。

关于c# - 如何使用/映射数据库 View 来填充包含的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1110399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com