主子关系批量加载子实体

by 周运禄 2012.11.23 14:42

注:脚本执行有风险,对于客户正式环境请在研发指导下执行。

具体需求如下:

A组合B

        

         代码一般都通过 A.Bs 访问其子实体集合

 

         A的实例有多个,且不能不循环时,如5000A,则每个A 的首次A.Bs访问,都会发起1个加载子实体的SQL查询。则会发起5000

        

平台基于稳定的考虑,在平台祁宏伟的帮助下,采用特定情况的特定代码方式实现。

 

如下面代码(TBData为主实体,组合 TBDataForumla  关系为1:0..N)【注:下面代码已经通过查询用途验证】

 

 

/// <summary>
        /// 批量预加载TBDataFormula
        /// </summary>
        /// <param name="tbDataList"></param>
        public static void BatchPreLoadTBDataFormula(TBData.EntityList tbDataList)
        {
            //批量预加载
            List<long> ids = new List<long>();
            foreach (TBData data in tbDataList)
            {
                data.SetRelation(TBData.EntityRes.TBDataForumla, new UFSoft.UBF.PL.ObjectAccess.POList<IPersistableObject>());
                if (!ids.Contains(data.ID)) ids.Add(data.ID);
            }
            UFIDA.U9.TB.TBData.TBDataForumla.EntityList dfList = UFIDA.U9.TB.TBData.TBDataForumla.Finder.FindAll(string.Format("{0} in ({1}) order by {0}"
                        , UFIDA.U9.TB.TBData.TBDataForumla.EntityRes.TBData, Helper.MyListParamName)
                , Helper.OptimizeIDListQuery(ids));

            if (dfList.Count > 0)
            {
                TBData currTBData = TBData.Finder.FindByID(dfList[0].TBDataKey.ID);
                IList currList = (IList)currTBData.GetRelation(TBData.EntityRes.TBDataForumla);

                foreach (TBDataForumla df in dfList)
                {
                    if (currTBData.ID != df.TBDataKey.ID)
                    {
                        //下一个TBData
                        currTBData = TBData.Finder.FindByID(df.TBDataKey.ID);
                        currList = (IList)currTBData.GetRelation(TBData.EntityRes.TBDataForumla);
                    }
                    currList.Add(df);
                    df.SetRelation(UFIDA.U9.TB.TBData.TBDataForumla.EntityRes.TBData, currTBData);
                    df.SetValue(UFIDA.U9.TB.TBData.TBDataForumla.EntityRes.TBData, currTBData.ID);
                }
            }

        }

评论 (7) -

hbzhang wrote at 2012/11/23 16:26:35 #

一次做到位呗,查询TBDataForumla用IDList方案,别又搞出一个巨大无比的SQL

Life Insurance Leads 美国 wrote at 2016/2/22 23:11:26 #

Hey! I could have sworn I've been to this site before but after reading through some of the post I realized it's new to me. Anyways, I'm definitely glad I found it and I'll be bookmarking and checking back often!

Mastercardexchangerate.Net 美国 wrote at 2016/3/24 7:19:20 #

Thanks on your marvelous posting! I certainly enjoyed reading it, you will be a great author.I will be sure to bookmark your blog and will often come back at some point. I want to encourage you continue your great job, have a nice weekend!

http://www.laviagraes.com/viagra-100-mg 美国 wrote at 2016/4/17 16:37:54 #

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?

lulur paling bagus 美国 wrote at 2017/1/22 12:02:38 #

When someone writes an article he/she retains the idea of a user in his/her mind that how a user can understand it. So that's why this post is amazing. Thanks!

gclub-royal1688 wrote at 2019/7/3 14:13:46 #

Thank you for the new information that is available to us to get full knowledge through this great website that makes it useful all the time.
https://www.gclub-royal1688.com/

gclub wrote at 2019/7/3 14:14:34 #

A good website with a quality that is reliable like this is the most amazing thing with new knowledge.
https://www.gclub45.com/

添加评论



biuquote
微笑得意调皮害羞酷大笑惊讶发呆喜欢可怜尴尬闭嘴噘嘴皱眉伤心抓狂呕吐坏笑漫骂发怒
Loading


RecentComments

评论 RSS

Statistics

989 篇文章
0 个单页
694657 条评论
11 次评分
409346 次访问
访问统计开始于 2019年12月15日
平均日访问 6202 次
当前 96 人在线