简体   繁体   English

如何将字典结果绑定到 class object c# linq

[英]how to bind dictionary result to class object c# linq

   Dictionary<Guid, string> flexEventTriggers = RepositoryContainer.GBM.Flex.Admin_FlexTriggerEvents.AsQueryable()
               .Where(x => flexEventTriggerIds.Contains(x.RecordID)).ToDictionary(x => x.RecordID, x => x.Name);
            Dictionary<Guid, string> lookupEntities = RepositoryContainer.GBM.Flex.Admin_LookupEntities.AsQueryable()
                           .Where(x => lookupEnityIds.Contains(x.RecordID)).ToDictionary(x => x.RecordID, x => x.Name);
            Dictionary<Guid, string> documents = RepositoryContainer.IDB.Flex.Documents.AsQueryable()
                           .Where(x => DocumentRecordIds.Contains(x.RecordID)).ToDictionary(x => x.RecordID, x => x.Name);




            foreach (var log in flexEventTriggerLogsList)
            {
                if (DocumentRecordIds.Count > 0)
                {
                    foreach (var dcoumentId in DocumentRecordIds)
                    {
                        //Fetch DocumentId's, LookupEntity_RecordID,  FlexEventTrigger_RecordID from log additional data
                        flexEventTriggerLogs.Add(new FlexEventTriggerLog
                        {
                            Name = documents[documentId],
                            Event_Name = flexEventTriggers[FlexTriggerEventRecordID],
                            Action_Name = lookupEntities[Entity_RecordID],
                        });

                    }
                }

How will I assign data to my object in foreach loop for Name, Event_Name, Action_Name.如何在 foreach 循环中为 Name、Event_Name、Action_Name 分配数据给我的 object。 Currently it is giving error in below code.目前它在下面的代码中给出错误。

                        Name = documents[documentId],
                        Event_Name = flexEventTriggers[FlexTriggerEventRecordID],
                        Action_Name = lookupEntities[Entity_RecordID],
                  

Be sure your DocumentRecordIds is type of List<Guid> and the property( Name, Event_Name, Action_Name ) should be type of string .确保您的DocumentRecordIdsList<Guid>类型,并且属性( Name, Event_Name, Action_Name )应该是string类型。

You could also try this:你也可以试试这个:

Name = documents.Where(p => p.Key == dcoumentId).Select(p => p.Value).FirstOrDefault();

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

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