c# - 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; }
}
提前致谢
解决方案
推荐阅读
- jquery - 在浮动元素中添加字段时,jQueryUI datepicker 1.12.1 和 jQuery 3.5.1 位置错误
- selenium - 我可以使用带参数的黄瓜钩吗
- laravel - OctoberCMS (Laravel) 字段选择语句
- kubernetes - Ingress Controller 和 Ingress 如何协同工作?
- python - 有谁知道在python中评估公式维度的更好方法?
- sql-server - 如何在 TSQL 中获取子字符串
- google-cloud-platform - 属性“notification_channels”的值不合适:元素 0:字符串
- rabbitmq - 具有持久特性的 RabbitMQ HA
- .htaccess - 将 htaccess 重写迁移到 nginx
- json - SwifiUI json 错误“EXC_BAD_ACCESS(代码=1,地址=0x5c8)。”