Skip to main content
 首页 » 编程设计

c#之如何将字符串转换为 System.Data.Objects.ObjectQuery`1[System.String]

2024年02月23日26bluestorm

我有一个表 Quotation 存储每个进行报价的用户的 QuotationNumber。 现在我想在我的 View 中打印出 QuotationNumber。

这是我在 Controller 中查询的内容:

Quotation iq = new Quotation(); 
 
string test = (from i in Quotations 
              where i.CustomerID == c.ID 
              select i.QuotationNumber).ToString(); 

当我显示测试时,它被输出:

System.Data.Objects.ObjectQuery`1[System.String] 

谁能告诉我解决方案。谢谢。

请您参考如下方法:

试试这个:

List<string> test = (from i in Quotations 
              where i.CustomerID == c.ID 
              select i.QuotationNumber).ToList(); 

然后遍历所有结果:

foreach (string quotationNumber in test) 
{ 
    Console.WriteLine("Found {0}", quotationNumber); 
}