我对Nhibernate集合的缓存有问题。 (Nhibernate 4.0和4.1) A类有B类的集合。
启用了启用和查询缓存中的辅助缓存。
A类和B类的对象总是在缓存中,只读用于应用程序。
但是当我在第二时间得到A类的实体时,我可以看到2个案例:
虽然B的所有对象都放在了二级缓存中 - 我已经验证了它。 我确保如果我通过Id得到B类实体,它从缓存中加载实体。 真的可以从缓存中获取集合吗?
[Class(Table = "MarginAgreement",Mutable=false )]
[Cache(Usage = CacheUsage.ReadOnly)]
public partial class MarginAgreement:object
{
int _id=default(int);
/// <summary>
/// NoComment
/// </summary>
[Id(0, Name = "id", Column = "id", TypeType = typeof(int) )]
[Generator(1, Class = "native")]
public virtual int id
{
get{ return _id ;} //
protected internal set{ _id=value;}
}
[NonSerialized]
protected IList<MarginAgreementMarginSystems> _MarginSystems = new List<MarginAgreementMarginSystems>();
[Bag(0, Table = "MarginAgreementMarginSystems", Inverse = true, Lazy = CollectionLazy.False )]
[Cache(1, Usage=CacheUsage.ReadOnly)]
[Key(2, Column = "MarginAgreement")]
[OneToMany(3, ClassType = typeof(MarginAgreementMarginSystems))]
public virtual IList<MarginAgreementMarginSystems> MarginSystems
{
get { return _MarginSystems; }
set { _MarginSystems = value; }
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
var equalObj= obj as _BaseObjects.MarginAgreement;
if (equalObj == null)
return false;
return (this.id ==equalObj.id);
}
public override int GetHashCode()
{
return (this.id ).GetHashCode();
}
}
[Class(Table = "MarginAgreementMarginSystems",Mutable=false )]
[Cache(Usage = CacheUsage.ReadOnly)]
public partial class MarginAgreementMarginSystems:object
{
int _id=default(int);
/// <summary>
/// NoComment
/// </summary>
[Id(0, Name = "id", Column = "id", TypeType = typeof(int) )]
[Generator(1, Class = "native")]
public virtual int id
{
get{ return _id ;} //
protected internal set{ _id=value;}
}
int _MarginAgreement=default(int);
/// <summary>
/// NoComment
/// </summary>
[Property(Name = "MarginAgreement", Column = "MarginAgreement", TypeType = typeof(int) , NotNull=true )]
public virtual int MarginAgreement
{
get{ return _MarginAgreement ;} //
protected internal set{ _MarginAgreement=value;}
}
margin_system _MarginSystem=default(margin_system);
/// <summary>
/// NoComment
/// </summary>
[Property(Name = "MarginSystem", Column = "MarginSystem", TypeType = typeof(margin_system) , NotNull=true )]
public virtual margin_system MarginSystem
{
get{ return _MarginSystem ;} //
protected internal set{ _MarginSystem=value;}
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
var equalObj= obj as _BaseObjects.MarginAgreementMarginSystems;
if (equalObj == null)
return false;
return (this.id ==equalObj.id);
}
public override int GetHashCode()
{
return (this.id ).GetHashCode();
}
}