如何将list< string>中的值与project.models.class进行比较?

ia2d9nvy  于 2021-07-24  发布在  Java
关注(0)|答案(2)|浏览(373)

我想使用linq从project.models.transaction\u details中检索数据,比较字符串列表(list)中的值。
这是我的密码

List<transaction_details> transactions = new List<transaction_details>();
List<string> date_list = new List<string>();
// date_list  output is ["2020-01-01","2020-01-02",2020-01-03",...,"2020-01-31"]

         while (sdr.Read())
                {
                    transactions.Add(new transaction_details
                    {
                            ID = sdr.GetInt32("ID"),
                            Transdate = sdr.GetDateTime("Transdate"),
                            Debit = sdr.GetDecimal("Debit"),
                            TransactionName =sdr.GetString("TransactionName"),
                            BranchID = sdr.GetString("BranchID")
                    });
                }
 var array1Index = date_list.Select((i, index) => new { Index = index, i = i }).ToList();
 List<transaction_details> arrayresult = new List<transaction_details>();

                var query1 = from a in array1Index
                             select transactions.Contains(a.i) == true ? a.i : "";

                arrayresult = query1.ToList();
                arrayresult.ForEach(x => {
                    Console.Write(x + " ");
                });

我的问题是(人工智能)是个错误。无法将“string”转换为“project.models.transaction\u details”。

vnjpjtjt

vnjpjtjt1#

你可能想查一下交易日期。试试这个:

var query1 = from a in array1Index
    select transactions.Any(t => t.Transdate == a.i) == true ? a.i : "";

编辑:如果需要事务列表,请尝试以下操作:

var query1 = from t in transactions
             where array1Index.Any(a => a.i == t.Transdate)
             select t;
flvtvl50

flvtvl502#

var query1 = from t in transactions
         where array1Index.Any(a => a.i == t.Transdate);

试试这个

相关问题