简体   繁体   English

的含义: <entity> 因为它不支持实体级别的惰性”

[英]Meaning of 'Disabled ghost property fetching for <entity> because it does not support lazy at the entity level'

I have seen this warning in my NHibernate-DataAccess: 我在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: 更新类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: 更新类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> ? 您是否尝试过使用 Iesi.Collections.Generic.ISet<Company>代替 *) ICollection<Company> IIRC, NHibernate used different interface set than EF or other typical libraries. IIRC,NHibernate使用了与EF或其他典型库不同的接口集。 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. 通常的问题是,ICollection在这里是很糟糕的合同,因为它没有声明“ SET”行为,实际上每个关系都是如此。

edit: *) I just found out that I were wrong, NH can cooperate with ICollection interface ( https://stackoverflow.com/a/4673125/717732 ). 编辑:*)我刚刚发现我错了,NH可以与ICollection接口( https://stackoverflow.com/a/4673125/717732 )合作。 Still you can try with ISet or HashSet, but I now doubt that that's the problem, sorry :/ 仍然可以尝试使用ISet或HashSet,但是我现在怀疑那是问题所在,对不起:/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM