首页 > 解决方案 > C# Linq 将合并列表设置为数据源

问题描述

我目前正在合并到列表将是gridview 的数据源。这是我的代码:

            // Get models
            var products = await API.Zelkon.Products.GetAll();
            var productsCurrencies = await API.Zelkon.CurrenciesBackend.Get();

            // Merge lists
            var results = products.Item1.Zip(productsCurrencies.Item1, (x, y) => new Tuple<Models.Products, Models.Zelkon.CurrenciesBackend>(x, y));

            // Create datasource
            var datasource = results.Select(r => new { r.Item2.price, r.Item2.setup_fee, r.Item1.product_number });

            GridProducts.DataSource = datasource;
            //  GridProducts.VisibleColumns("name");
            UI.CustomizeGridDefault(GridProducts);

我的问题是 的值r.Item2.setup_fee始终是第一行的值。我已经检查了集合,那里的数据是正确的。

难道我做错了什么?

下面是结构:

 class CurrenciesBackend
    {
        public string currency_name { get; set; }
        public string currency_code { get; set; }
        public double price { get; set; }
        public double recommended_price { get; set; }
        public double setup_fee { get; set; }
        public int product_number { get; set; }
    }

class Products
    {
        public string name { get; set; }
        public string description { get; set; }
        public string invoice_layout { get; set; }
        public string layout_number { get; set; }
        public string payment_terms_name { get; set; }
        public string payment_terms_number { get; set; }
        public DateTime creation_date { get; set; }
        public int enabled { get; set; }
        public int is_subscription { get; set; }
        public int is_delivery_required { get; set; }
        public int allow_discount { get; set; }
        public int allow_trial { get; set; }
        public int max_discount { get; set; }
        public int max_discount_duration { get; set; }
        public int vat_percentage { get; set; }
        public int trial_period { get; set; }
        public int binding_period { get; set; }
        public int days_of_credit { get; set; }
        public int unit { get; set; }
        public string allowed_country_codes { get; set; }
        public int product_number { get; set; }
        public int authorize_invoice { get; set; }

    }

提前致谢

标签: c#listlinqmodel

解决方案


推荐阅读