'为< entity>禁用的ghost属性获取的含义因为它不支持实体层面的懒惰“ [英] Meaning of 'Disabled ghost property fetching for <entity> because it does not support lazy at the entity level'

查看:282
本文介绍了'为< entity>禁用的ghost属性获取的含义因为它不支持实体层面的懒惰“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


'禁用实体的ghost属性获取因为它不支持实体级别的懒惰'

有人知道,这是什么意思? -

下面是一个实体的映射,它引发了这个警告:

  public class BusinessTypeMap:ClassMap< BusinessType> {
public BusinessTypeMap(){
this.Table(BusinessType);

this.Version(x => x.ObjectVersion);
this.Id(x => x.Id).GeneratedBy.Assigned();

this.Map(x => x.Key).Length(8).Nullable();
this.Map(x => x.Name).Length(50).Not.Nullable();
this.Map(x => x.Comment).Length(8000).Nullable();

this.Map(x => x.Created).Not.Nullable()。Not.OptimisticLock();
this.Map(x => x.CreatedBy).Length(255).Not.Nullable()。Not.OptimisticLock();
this.Map(x => x.Changed).Nullable()。Not.OptimisticLock();
this.Map(x => x.ChangedBy).Length(255).Nullable()。Not.OptimisticLock();

this.HasMany(x => x.LocalizedProperties).AsSet()。KeyColumn(EntityId)。Where(LocalizedEntityClass ='Prayon.Entities.BusinessType')。ForeignKeyConstraintName(无)Cascade.All();
this.HasMany(x => x.Companys).AsSet()。KeyColumn(BusinessTypeId)。Fetch.Select()。Inverse()。Cascade.None();
this.References(x => x.Client).Column(ClientId)。Fetch.Select();




$ p $更新了BusinessTypeBase类的定义:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'$ $'$ $'$ $'$ $'$ $'$ $'$ $' #region专用变量

保护字符串键;
保护字符串名称;
保护字符串评论;
$ b #endregion

#region构造函数
$ b $保护BusinessTypeBase(){
this.LocalizedProperties = new HashSet< LocalizedProperty>();

OnCreated();

$ b protected BusinessTypeBase(Guid id,String key,String name,String comment){
this.LocalizedProperties = new HashSet< LocalizedProperty>();

this.id = id;
this.key = key;
this.name = name;
this.comment = comment;
OnCreated();


protected BusinessTypeBase(Guid id,String name){
this.LocalizedProperties = new HashSet< LocalizedProperty>();

this.id = id;
this.name = name;
OnCreated();
}

#endregion

#region Puplic属性

公共虚拟字符串键{
get {return key; }
set {
if(this.key!= value){
this.OnKeyChanging(value);
this.key = value;
this.OnKeyChanged();
}
}
}



///< summary>
/// @loc
///< / summary>
[Localize(Name)]
public virtual String Name {
get {return name; }
set {
if(this.name!= value){
this.OnNameChanging(value);
this.name = value;
this.OnNameChanged();



$ b public virtual String NameLocalized {
get {return this.GetLocalized(x => x.Name); }
set {
if(this.NameLocalized!= value){
this.OnNameLocalizedChanging(value);
this.AddLocalizedProperty(x => x.Name,value);
this.OnNameLocalizedChanged();
if(string.IsNullOrEmpty(this.Name)){
this.Name = value;




$ b protected void OnNameLocalizedChanging(String value){
}

protected virtual void OnNameLocalizedChanged(){
}



[IgnoreForDeleteSerialization]
public virtual String Comment {
get {return comment; }
set {
if(this.comment!= value){
this.OnCommentChanging(value);
this.comment = value;
this.OnCommentChanged();





$ b #endregion

#region版本

保护Int32 objectVersion;

public virtual Int32 ObjectVersion {
get {return objectVersion; }
set {
if(this.objectVersion!= value){
this.objectVersion = value;



$ b #endregion

#region CollectionRules

public override string [] CollectionRules {
得到{return collectionRules; }


private static readonly string [] collectionRules = new string []
{
Prayon.Entities.Client.BusinessTypes
};

#endregion


#region Company Association

保护虚拟无效OnCompanysChanging(ICollection<公司>值){
}

protected void OnCompanysChanged(){
}

private ICollection< Company> companys = new HashSet< Company>();

[IgnoreForDeleteSerialization]
公共虚拟ICollection<公司>公司{
得到{return companys; }
set {
if(this.companys!= value){
this.OnCompanysChanging(value);
this.companys = value;
this.OnCompanysChanged();





$ b #endregion

#region客户关联

public virtual Guid SerializableClient {
get {return(this.Client == null?(this.SerializationProxies.ContainsKey(ClientId)?this.SerializationProxies [ClientId]:Guid.Empty):this .Client.Id); }
set {this.SerializationProxies [ClientId] = value; }

$ b $保护虚拟无效OnClientChanging(客户端值){
}

保护虚拟无效OnClientChanged(){
}

私人客户端客户端;

[IgnoreForDeleteSerialization]
公共虚拟客户端客户端{
get {return client; }
set {
if(this.client!= value){
this.OnClientChanging(value);
this.client = value;
this.OnClientChanged();
}
}
}

#endregion

#region ICloneable成员

///<总结>
///返回BusinessType的类型化副本
///< / summary>
公共虚拟对象Clone(){
BusinessType copy = new BusinessType();
copy.id = this.id;
copy.key = this.key;
copy.name = this.name;
copy.comment = this.comment;
返回副本;
}

#endregion

#region检查平等

///< summary>
///检查通过的参数是否等于这个地址的值。
///< / summary>
///< param name =obj>对象将被比较为< / param>
///< returns>如果Equal else False< / returns>则为真
public override bool Equals(object obj){
if(obj is BusinessTypeBase){
var entity = obj as BusinessTypeBase;
if(entity.id!= this.id)
return false;
if(entity.key!= this.key)
return false;
if(entity.name!= this.name)
return false;
if(entity.comment!= this.comment)
return false;
返回true;
}
return base.Equals(obj);


public override int GetHashCode(){
int hash = 0;
hash = hash ^ this.id.GetHashCode();
if(this.key!= null){
hash = hash ^ this.key.GetHashCode();

if(this.name!= null){
hash = hash ^ this.name.GetHashCode();

if(this.comment!= null){
hash = hash ^ this.comment.GetHashCode();
}

返回散列;

$ b $ public static bool operator ==(BusinessTypeBase obj1,BusinessTypeBase obj2){
if(object.ReferenceEquals(obj1,null)&& object.ReferenceEquals(obj2 ,null)){
return true;

if(object.ReferenceEquals(obj1,null)|| object.ReferenceEquals(obj2,null)){
return false;
}
return obj1.Equals(obj2);

$ b $ public static bool operator!=(BusinessTypeBase obj1,BusinessTypeBase obj2){
return!(obj1 == obj2);
}

#endregion

#region To String

///< summary>
///覆盖ToString来产生当前对象的XML格式
///< / summary>
public override string ToString(){
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendFormat(< Id> {0}< / Id> {1},this.id.ToString(),System.Environment.NewLine);
if(this.key!= null)
stringBuilder.AppendFormat(< Key> {0}< / Key> {1},this.key.ToString(),System.Environment 。新队);
if(this.name!= null)
stringBuilder.AppendFormat(< Name> {0}< / Name> {1},this.name.ToString(),System.Environment 。新队);
if(this.comment!= null)
stringBuilder.AppendFormat(< Comment> {0}< / Comment> {1},this.comment.ToString(),System.Environment 。新队);
return stringBuilder.ToString();


#endregion

#region扩展性方法定义

protected void OnCreated(){
}

protected void OnKeyChanging(String value){
}

protected void OnKeyChanged(){
}

保护虚拟void OnNameChanging(String value){
}

protected void OnNameChanged(){
}

protected void OnCommentChanging(String value){


protected void OnCommentChanged(){
}

#endregion

#region本地化

public virtual ICollection< LocalizedProperty> LocalizedProperties {get;组; }

#endregion
}

更新定义类BusinessType:

$ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
#region构造函数
$ b $ public BusinessType()
:base(){
}

public BusinessType(Guid id,String key,字符串名称,字符串注释)
:base(id,key,name,comment){
}
$ b $ public BusinessType(Guid id,String name)
:base (id,name){
}

#endregion
}


Iesi.Collections.Generic.ISet< Company> 而不是 > *) ICollection<公司> ? IIRC,NHibernate使用不同的接口设置比EF或其他典型的库。一般的问题是,ICollection在这里是相当不好的合同,因为它没有声明SET行为,实际上每一个关系都是这样。

编辑:
*)我刚发现我错了,NH可以配合ICollection接口( https://stackoverflow.com/a/4673125 / 717732 )。你仍然可以尝试使用ISet或HashSet,但我现在怀疑这是问题,抱歉:/ $ / $>

I have seen this warning in my NHibernate-DataAccess:

'Disabled ghost property fetching for entity because it does not support lazy at the entity level'

Does someone know, what does this mean? - What does I have to change to solve this?

Here is a mapping for an entity, which is causing this warning:

public class BusinessTypeMap : ClassMap<BusinessType> {
    public BusinessTypeMap() {
        this.Table("BusinessType");

        this.Version(x => x.ObjectVersion);
        this.Id(x => x.Id).GeneratedBy.Assigned();

        this.Map(x => x.Key).Length(8).Nullable(); 
        this.Map(x => x.Name).Length(50).Not.Nullable(); 
        this.Map(x => x.Comment).Length(8000).Nullable(); 

        this.Map(x => x.Created).Not.Nullable().Not.OptimisticLock();
        this.Map(x => x.CreatedBy).Length(255).Not.Nullable().Not.OptimisticLock();
        this.Map(x => x.Changed).Nullable().Not.OptimisticLock();
        this.Map(x => x.ChangedBy).Length(255).Nullable().Not.OptimisticLock();

        this.HasMany(x => x.LocalizedProperties).AsSet().KeyColumn("EntityId").Where("LocalizedEntityClass = 'Prayon.Entities.BusinessType'").ForeignKeyConstraintName("none").Cascade.All();
        this.HasMany(x => x.Companys).AsSet().KeyColumn("BusinessTypeId").Fetch.Select().Inverse().Cascade.None();
        this.References(x => x.Client).Column("ClientId").Fetch.Select();
    }
}

Update definition of class BusinessTypeBase:

[Serializable]
public abstract class BusinessTypeBase : AuditableEntityBase, ILocalizedEntity {

    #region Private Variables

    protected String key;
    protected String name;
    protected String comment;

    #endregion

    #region Constructors

    protected BusinessTypeBase() {
        this.LocalizedProperties = new HashSet<LocalizedProperty>();

        OnCreated();
    }

    protected BusinessTypeBase(Guid id, String key, String name, String comment) {
        this.LocalizedProperties = new HashSet<LocalizedProperty>();

        this.id = id;
        this.key = key;
        this.name = name;
        this.comment = comment;
        OnCreated();
    }

    protected BusinessTypeBase(Guid id, String name) {
        this.LocalizedProperties = new HashSet<LocalizedProperty>();

        this.id = id;
        this.name = name;
        OnCreated();
    }

    #endregion

    #region Puplic Properties

    public virtual String Key {
        get { return key; }
        set {
            if (this.key != value) {
                this.OnKeyChanging(value);
                this.key = value;
                this.OnKeyChanged();
            }
        }
    }



    /// <summary>
    /// @loc
    /// </summary>
    [Localize("Name")]
    public virtual String Name {
        get { return name; }
        set {
            if (this.name != value) {
                this.OnNameChanging(value);
                this.name = value;
                this.OnNameChanged();
            }
        }
    }

    public virtual String NameLocalized {
        get { return this.GetLocalized(x => x.Name); }
        set {
            if (this.NameLocalized != value) {
                this.OnNameLocalizedChanging(value);
                this.AddLocalizedProperty(x => x.Name, value);
                this.OnNameLocalizedChanged();
                if (string.IsNullOrEmpty(this.Name)) {
                    this.Name = value;
                }
            }
        }
    }

    protected virtual void OnNameLocalizedChanging(String value) {
    }

    protected virtual void OnNameLocalizedChanged() {
    }



    [IgnoreForDeleteSerialization]
    public virtual String Comment {
        get { return comment; }
        set {
            if (this.comment != value) {
                this.OnCommentChanging(value);
                this.comment = value;
                this.OnCommentChanged();
            }
        }
    }



    #endregion

    #region Version

    protected Int32 objectVersion;

    public virtual Int32 ObjectVersion {
        get { return objectVersion; }
        set {
            if (this.objectVersion != value) {
                this.objectVersion = value;
            }
        }
    }

    #endregion

    #region CollectionRules

    public override string[] CollectionRules {
        get { return collectionRules; }
    }

    private static readonly string[] collectionRules = new string[]
        {
            "Prayon.Entities.Client.BusinessTypes"
        };

    #endregion


    #region Company Association

    protected virtual void OnCompanysChanging(ICollection<Company> value) {
    }

    protected virtual void OnCompanysChanged() {
    }

    private ICollection<Company> companys = new HashSet<Company>();

    [IgnoreForDeleteSerialization]
    public virtual ICollection<Company> Companys {
        get { return companys; }
        set {
            if (this.companys != value) {
                this.OnCompanysChanging(value);
                this.companys = value;
                this.OnCompanysChanged();

            }

        }
    }

    #endregion

    #region Client Association

    public virtual Guid SerializableClient {
        get { return (this.Client == null ? (this.SerializationProxies.ContainsKey("ClientId") ? this.SerializationProxies["ClientId"] : Guid.Empty) : this.Client.Id); }
        set { this.SerializationProxies["ClientId"] = value; }
    }

    protected virtual void OnClientChanging(Client value) {
    }

    protected virtual void OnClientChanged() {
    }

    private Client client;

    [IgnoreForDeleteSerialization]
    public virtual Client Client {
        get { return client; }
        set {
            if (this.client != value) {
                this.OnClientChanging(value);
                this.client = value;
                this.OnClientChanged();
            }
        }
    }

    #endregion

    #region ICloneable Members

    ///<summary>
    ///  Returns a Typed Copy of BusinessType
    ///</summary>
    public virtual object Clone() {
        BusinessType copy = new BusinessType();
        copy.id = this.id;
        copy.key = this.key;
        copy.name = this.name;
        copy.comment = this.comment;
        return copy;
    }

    #endregion

    #region Check Equality

    /// <summary>
    /// Check if the Passed Parameter is value equaled to this Address.
    /// </summary>
    /// <param name="obj">The Object will ba compared to.</param>
    /// <returns>True if Equal else False</returns>
    public override bool Equals(object obj) {
        if (obj is BusinessTypeBase) {
            var entity = obj as BusinessTypeBase;
            if (entity.id != this.id)
                return false;
            if (entity.key != this.key)
                return false;
            if (entity.name != this.name)
                return false;
            if (entity.comment != this.comment)
                return false;
            return true;
        }
        return base.Equals(obj);
    }

    public override int GetHashCode() {
        int hash = 0;
        hash = hash ^ this.id.GetHashCode();
        if (this.key != null) {
            hash = hash ^ this.key.GetHashCode();
        }
        if (this.name != null) {
            hash = hash ^ this.name.GetHashCode();
        }
        if (this.comment != null) {
            hash = hash ^ this.comment.GetHashCode();
        }

        return hash;
    }

    public static bool operator ==(BusinessTypeBase obj1, BusinessTypeBase obj2) {
        if (object.ReferenceEquals(obj1, null) && object.ReferenceEquals(obj2, null)) {
            return true;
        }
        if (object.ReferenceEquals(obj1, null) || object.ReferenceEquals(obj2, null)) {
            return false;
        }
        return obj1.Equals(obj2);
    }

    public static bool operator !=(BusinessTypeBase obj1, BusinessTypeBase obj2) {
        return !(obj1 == obj2);
    }

    #endregion

    #region To String

    /// <summary>
    /// override ToString to produce XML format of the current object
    /// </summary>
    public override string ToString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.AppendFormat("<Id>{0}</Id>{1}", this.id.ToString(), System.Environment.NewLine);
        if (this.key != null)
            stringBuilder.AppendFormat("<Key>{0}</Key>{1}", this.key.ToString(), System.Environment.NewLine);
        if (this.name != null)
            stringBuilder.AppendFormat("<Name>{0}</Name>{1}", this.name.ToString(), System.Environment.NewLine);
        if (this.comment != null)
            stringBuilder.AppendFormat("<Comment>{0}</Comment>{1}", this.comment.ToString(), System.Environment.NewLine);
        return stringBuilder.ToString();
    }

    #endregion

    #region Extensibility Method Definitions

    protected virtual void OnCreated() {
    }

    protected virtual void OnKeyChanging(String value) {
    }

    protected virtual void OnKeyChanged() {
    }

    protected virtual void OnNameChanging(String value) {
    }

    protected virtual void OnNameChanged() {
    }

    protected virtual void OnCommentChanging(String value) {
    }

    protected virtual void OnCommentChanged() {
    }

    #endregion

    #region Localization

    public virtual ICollection<LocalizedProperty> LocalizedProperties { get; set; }

    #endregion
}

Update definition of class BusinessType:

[Serializable]
public partial class BusinessType : BusinessTypeBase {

    #region Constructors

    public BusinessType()
        : base() {
    }

    public BusinessType(Guid id, String key, String name, String comment)
        : base(id, key, name, comment) {
    }

    public BusinessType(Guid id, String name)
        : base(id, name) {
    }

    #endregion
}

解决方案

Have you tried using Iesi.Collections.Generic.ISet<Company> instead of *) ICollection<Company> ? IIRC, NHibernate used different interface set than EF or other typical libraries. The general problem is that ICollection is quite bad contract here, as it does not state the "SET" behaviour, which in fact every relation is.

edit: *) I just found out that I were wrong, NH can cooperate with ICollection interface (https://stackoverflow.com/a/4673125/717732). Still you can try with ISet or HashSet, but I now doubt that that's the problem, sorry :/

这篇关于'为&lt; entity&gt;禁用的ghost属性获取的含义因为它不支持实体层面的懒惰“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆