首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将'Mech‘的数据连接到'Tech’数据?

如何将'Mech‘的数据连接到'Tech’数据?
EN

Stack Overflow用户
提问于 2019-04-22 12:11:18
回答 1查看 56关注 0票数 0

我试图将“机械”的数据与“技术”的数据结合起来,但我不知道该怎么做。

这是我当前的代码,它列出了DecodedFactoryOptions下的所有数据:首先,我按每个设备的类别进行分组。

代码语言:javascript
复制
 public static IEnumerable<VehicleFactoryOptionModel> GetFactoryOptions(IEnumerable<DecodedFactoryOption> options)
        {
            var optionEquipment = new List<VehicleFactoryOptionModel>();

            if (options == null) return optionEquipment;

            var optEquip = options.GroupBy(e => e.Category);

            foreach (var equip in optEquip)
            {
                var optionalEquipment = new VehicleFactoryOptionModel { Data = new List<VehicleCategoryOptionModel>()};

                if (equip != null)
                {
                    foreach (var eq in equip)
                    {
                        optionalEquipment.TypeId = eq.OptionHeaderId;
                        optionalEquipment.Description = eq.Description;
                        optionalEquipment.Data.Select(d => d.StyleIds == eq.AppliedStyleId);
                        optionalEquipment.chromeCode = eq.chromeCode;
                        optionalEquipment.oemCode = eq.oemCode;
                        optionalEquipment.optionKindId = eq.optionKindId;
                        if (eq.OptionCategoryId == null) continue;
                        FillOptionCategoryInfo(eq, optionalEquipment);
                    }
                }

                optionEquipment.Add(optionalEquipment);
            }

            return optionEquipment;
        }

上面代码的结果是:

代码语言:javascript
复制
[
    {
        "TypeId": 1236,
        "TypeName": "MECHANICAL",
        "Data": [
            {
                "Description": "Engine: 5.7L V8 DOHC 32V FFV w/i-Force",
                "Categories": [
                    {
                        "Id": 1052,
                        "Name": "Engine-8 Cyl"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },
            {
                "Description": "Engine: 5.7L V8 DOHC 32V FFV w/i-Force",
                "Categories": [
                    {
                        "Id": 1213,
                        "Name": "Fuel System-Flex Fuel"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            }
    },
    {
        "TypeId": 1176,
        "TypeName": "TECHNICAL",
        "Data": [
            {
                "Description": "Tires: P275/55R20 Bridgestone/Dunlop Performance",
                "Categories": [
                    {
                        "Id": 1092,
                        "Name": "Tire-Front-Performance"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },
            {
                "Description": "Tires: P275/55R20 Bridgestone/Dunlop Performance",
                "Categories": [
                    {
                        "Id": 1097,
                        "Name": "Tire-Rear-Performance"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },
    {
        "TypeId": 10689,
        "TypeName": "ENTERTAINMENT",
        "Data": [
            {
                "Description": "Radio: Entune Premium w/JBL Audio & Navigation -inc: AM/FM/HD radio, CD player MP3/WMA playback capability, high-resolution 7\" touch-screen display, auxiliary audio jack, USB 2.0 port, iPod connectivity and control, iTunes Tagging, traffic and weather, JBL speakers and amplifier, Bluetooth hands-free phone capability, phone book access, voice recognition and music streaming, Entune App Suite includes Bing, iHeartRadio, MovieTickets.com, OpenTable, Pandora, Yelp and Facebook Places; real-time info including traffic, weather, fuel prices, sports and stocks, SIRIUSXM Satellite Radio, 90-day free trial",
                "Categories": [
                    {
                        "Id": 1014,
                        "Name": "Audio-AM/FM Stereo"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },
            {
                "Description": "Radio: Entune Premium w/JBL Audio & Navigation -inc: AM/FM/HD radio, CD player MP3/WMA playback capability, high-resolution 7\" touch-screen display, auxiliary audio jack, USB 2.0 port, iPod connectivity and control, iTunes Tagging, traffic and weather, JBL speakers and amplifier, Bluetooth hands-free phone capability, phone book access, voice recognition and music streaming, Entune App Suite includes Bing, iHeartRadio, MovieTickets.com, OpenTable, Pandora, Yelp and Facebook Places; real-time info including traffic, weather, fuel prices, sports and stocks, SIRIUSXM Satellite Radio, 90-day free trial",
                "Categories": [
                    {
                        "Id": 1017,
                        "Name": "Audio-CD Player"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },

我希望“机械”的数据将连接到“技术”数据。

这是我想要的结果:

代码语言:javascript
复制
{
        "TypeId": 1176,
        "TypeName": "TECHNICAL",
        "Data": [
            {
                "Description": "Tires: P275/55R20 Bridgestone/Dunlop Performance",
                "Categories": [
                    {
                        "Id": 1092,
                        "Name": "Tire-Front-Performance"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },
            {
                "Description": "Tires: P275/55R20 Bridgestone/Dunlop Performance",
                "Categories": [
                    {
                        "Id": 1097,
                        "Name": "Tire-Rear-Performance"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },

                "Description": "Engine: 5.7L V8 DOHC 32V FFV w/i-Force",
                "Categories": [
                    {
                        "Id": 1052,
                        "Name": "Engine-8 Cyl"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            },
            {
                "Description": "Engine: 5.7L V8 DOHC 32V FFV w/i-Force",
                "Categories": [
                    {
                        "Id": 1213,
                        "Name": "Fuel System-Flex Fuel"
                    }
                ],
                "StyleIds": [
                    362074,
                    362107
                ]
            }
    {
EN

回答 1

Stack Overflow用户

发布于 2019-04-22 12:43:22

下面的代码将会起作用,请记住我没有测试过

代码语言:javascript
复制
  // instead of new add the call to get the Ienumerable
  IEnumerable<VehicleFactoryOptionModel> optionModels = new List<VehicleFactoryOptionModel>();
  // fill type name and id for the technical
  var result = optionModels.Select(x => new {x.TypeId, x.TypeName, x.Data}).
      Where(x => x.TypeName.ToString() == "Technical").ToList();

  // select only the data list for mechanical
  var test = optionModels.
      Where(x=>x.TypeName.ToString() == "Mechanical").SelectMany(x=>x.Data );

  // add it to the technical list,
  // assumption that there will be only one list for the techincal..thats why the index 0
  result[0].Data.AddRange(test);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55789016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档