亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 EntityCollection 檢索單個值的最快方法

從 EntityCollection 檢索單個值的最快方法

C#
忽然笑 2022-07-23 17:06:45
我有一個 Entitycollection,我將其轉換為一個列表,如下所示:var List = Lines.Entities.Where(p =>                    p.GetAttributeValue<OptionSetValue>("new_time").Value == 100000003).Select(e =>                    new {                        group = e.GetAttributeValue<OptionSetValue>("new_group"),                        desc = e.GetAttributeValue<string>("new_desc"),                        numbers = new Dictionary<string, int>()                            {                                {"monday", e.GetAttributeValue<int>("new_mondayunits") },                                {"tuesday", e.GetAttributeValue<int>("new_tuesdayunits") },                                {"wednesday", e.GetAttributeValue<int>("new_wednesdayunits")},                                {"thursday", e.GetAttributeValue<int>("new_thursdayunits") },                                {"friday", e.GetAttributeValue<int>("new_fridayunits") }                            }                    }).ToList();我在我想要的那一天檢索值,如下所示:var value = List.Where(e => e.group == group && e.desc == desc).Select(e => e.numbers["monday"]);我的意圖是以最快的方式從 EntityCollection 中檢索值,因為這些值是從 for 循環中調用的。我不確定將 entitycollection 轉換為列表是否有幫助。這是實體集合:                    string fetchContractLines = @"                          <fetch version='1.0' output-format='xml-platform' mapping='logical'>                            <entity name='new_contractline'>                                <attribute name='new_group' />                                <attribute name='new_desc' />                                <attribute name='new_time' />                                <attribute name='new_mondayunits' />                                <attribute name='new_tuesdayunits' />                                <attribute name='new_wednesdayunits' />                                <attribute name='new_thursdayunits' />                                <attribute name='new_fridayunits' />我需要速度的原因是我達到了插件執行的 2 分鐘限制,并認為我可以通過減少查找時間來減少所需的時間。
查看完整描述

1 回答

?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

我改用字典,但仍然不確定是否有更快的方法從集合中檢索值:


var Lookup = Lines.Entities.Where(e => e.GetAttributeValue<OptionSetValue>("new_time").Value == 100000001).Select(r => new

                    {

                        group = r.GetAttributeValue<OptionSetValue>("new_group").Value,

                        desc = r.GetAttributeValue<string>("new_desc"),

                        numbers = new Dictionary<string, int>()

                        {

                            {"monday", r.GetAttributeValue<int>("new_mondayunits") },

                            {"tuesday", r.GetAttributeValue<int>("new_tuesdayunits") },

                            {"wednesday", r.GetAttributeValue<int>("new_wednesdayunits") },

                            {"thursday", r.GetAttributeValue<int>("new_thursdayunits") },

                            {"friday", r.GetAttributeValue<int>("new_fridayunits") }

                        }

                    }).ToDictionary(t => t.group.ToString() + t.desc, t => t.numbers);

var quan = Lookup.ContainsKey(key) ? amLookup[key][currentday] : 0;


查看完整回答
反對 回復 2022-07-23
  • 1 回答
  • 0 關注
  • 102 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號