【问题标题】:how to bind dictionary result to class object c# linq如何将字典结果绑定到类对象c#linq
【发布时间】:2021-06-16 15:11:37
【问题描述】:
   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],
                        });

                    }
                }

我将如何在 foreach 循环中为 Name、Event_Name、Action_Name 的对象分配数据。目前它在下面的代码中给出错误。

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

【问题讨论】:

  • 那么,错误详情是什么?

标签: c# json asp.net-mvc linq asp.net-core


【解决方案1】:

确保您的DocumentRecordIds 是List&lt;Guid&gt; 的类型,并且属性(Name, Event_Name, Action_Name) 应该是string 的类型。

你也可以试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    相关资源
    最近更新 更多