我有一个复合身份class_tier_info_id
,item_type_id
,stage
的实体:
public class ClassTierItemTypeUpgrade : IEquatable<ClassTierItemTypeUpgrade>
{
public virtual ClassTierInfo ClassTier { get; set; } // key-part
public virtual ItemType ItemType { get; set; } // key-part
public virtual int Stage { get; set; } // key-part
public virtual int Value { get; set; }
public virtual bool Equals(ClassTierItemTypeUpgrade other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(ClassTier, other.ClassTier) && Equals(ItemType, other.ItemType) && Stage == other.Stage;
}
public override bool Equals(object obj) // ...
public override int GetHashCode() // ...
}
mapping.CompositeId()
.KeyReference(x => x.ItemType, DbNamingHelper.FormatColumnName(nameof(ClassTierItemTypeUpgrade.ItemType)) + "_id")
.KeyReference(x => x.ClassTier, DbNamingHelper.FormatColumnName(nameof(ClassTierItemTypeUpgrade.ClassTier)) + "_id")
.KeyProperty(x => x.Stage);
// Value is auto-mapped
mapping.Schema("public");
mapping.Cache.Region("Static");
mapping.Cache.ReadOnly();
mapping.ReadOnly();
此实体从另一个实体ItemType
(自动映射,相同的缓存区域)引用:
public class ItemType
{
public virtual int Id { get; set; }
public virtual Iesi.Collections.Generic.ISet<ClassTierItemTypeUpgrade> TierUpgrades { get; set; }
= new HashedSet<ClassTierItemTypeUpgrade>();
// ...other properties...
}
所有ItemType
和ClassTierItemTypeUpgrade
实体都已预加载,应放在二级缓存中。
但是当加载引用ItemType
的其他实体时,我在查询日志中看到:
SELECT tierupgrad0_.item_type_id as item1_1_,
tierupgrad0_.class_tier_id as class2_1_,
tierupgrad0_.Stage as Stage1_,
tierupgrad0_.item_type_id as item1_21_0_,
tierupgrad0_.class_tier_id as class2_21_0_,
tierupgrad0_.Stage as Stage21_0_,
tierupgrad0_.value as value21_0_
FROM public.class_tier_item_type_upgrade_infos tierupgrad0_
WHERE tierupgrad0_.item_type_id = 5 /* :p0 */
表示未正确使用二级缓存。
但ItemType
实体本身实际上是从二级缓存加载的。
为什么会发生这种情况,我该如何解决?
答案 0 :(得分:0)
集合缓存设置应与表(每个集合)分开指定:
// instance is ICollectionInstance
instance.Cache.Region("Region");
instance.Cache.ReadOnly();
但后来我another problem所以现在我没有使用它。