初始化[Unavailable#] - 懒得初始化集合,没有关闭会话或会话

时间:2014-05-08 09:32:44

标签: session c#-4.0 nhibernate fluent-nhibernate

我有一个名为fixture的类,它有两个属性描述和日期。现在我不想直接操作thi stwo属性,但我想操作一些集合对象" Allattribute"在这个例子中,我感觉在每个属性的get和set中。

retrival工作正常,但我坚持得到这个错误

初始化[Unavailable#] - 懒得初始化一个集合,没有会话或会话被关闭。

Model和Mapper的代码如下:

public class Fixture:EntityBase     {

    public Fixture() {
        //PogObject = new List<PogObject>();
        //ObjectFixtureDate = new List<Objectfixturedate>();
    }
        public virtual long IDPOGObject { get; set; }
    private ObservableCollection<DictionaryEntry> m_allattributes = new ObservableCollection<DictionaryEntry>();
    private IList<FixtureDate> mFixtureDate = new List<FixtureDate>();
    private IList<FixtureDesc> mFixtureDesc = new List<FixtureDesc>();
    private IList<FixtureFlag> mFixtureFlag = new List<FixtureFlag>();


    public virtual IList<FixtureDate> FixtureDate
    {
        get
        {
            mFixtureDate.Clear();
            foreach (var item in m_allattributes)
            {
                if (item.Value is FixtureDate)
                {
                    mFixtureDate.Add((FixtureDate)item.Value);
                }
            }

            return mFixtureDate;
        }


        set
        {
            //try
            //{
                if (value.Count != 0)
                {
                    foreach (var item in value)
                    {
                        DictionaryEntry dEntry = new DictionaryEntry(item.Dictionary.DictionaryName, item);
                        if (!m_allattributes.Contains(dEntry))
                        {
                            m_allattributes.Add(dEntry);
                        }
                    }
                }
            //}
            //catch (Exception ex)
            //{

            //}

            mFixtureDate = value;
        }
    }


    public virtual IList<FixtureDesc> FixtureDescription
    {
        get
        {
            mFixtureDesc.Clear();
            foreach (var item in m_allattributes)
            {
                if (item.Value is FixtureDesc)
                {
                    if (!mFixtureDesc.Contains((FixtureDesc)item.Value))
                    {
                        mFixtureDesc.Add((FixtureDesc)item.Value);
                    }
                }
            }

            return mFixtureDesc;
        }


        set
        {
            if (value.Count != 0)
            {
                foreach (var item in value)
                {
                    DictionaryEntry dEntry = new DictionaryEntry(item.Dictionary.DictionaryName, item);

                    // DictionaryEntry dEntry = new DictionaryEntry(item.DescNum, item);
                    if (!m_allattributes.Contains(dEntry))
                    {
                        m_allattributes.Add(dEntry);
                    }
                }
            }

            mFixtureDesc = value;

        }
    }




}
  • Mapper类:

公共类FixtureMap:ClassMap {

    public FixtureMap() {
        Table("SPOG_ObjectFixture");
        Not.LazyLoad();
        Id(x => x.IDPOGObject).GeneratedBy.Foreign("PogObject");
        HasMany(x => x.FixtureDescription).Cascade.AllDeleteOrphan().Inverse().Not.LazyLoad().KeyColumn("IDPOGObject").Fetch.Join();
        HasMany(x => x.FixtureDate).Cascade.AllDeleteOrphan().Inverse().Not.LazyLoad().KeyColumn("IDPOGObject");

    }
}

0 个答案:

没有答案