简体   繁体   中英

Linq “Sequence operators not supported for type” Exception

I'm trying to write a linq query which populates a dataGridView:

dataGridViewNorthWind.DataSource = (from products in dc.Products where 
         products.ProductName.StartsWith("C") && products.ProductName.Contains('a') 
         select new { products.ProductName, products.Category });

but I'm getting an "Sequence operators not supported for type string" exception. What`s wrong here?

PS. Any tips on building better queries are welcome, it`s my very first contact with Linq :)

I think the problem is you cant use the Contains method in the way you're hoping. But, you can try this, I changed the argument to the Contains method from a char to a string

dataGridViewNorthWind.DataSource = (from products in dc.Products where 
         products.ProductName.StartsWith("C") && products.ProductName.Contains("a") 
         select new { products.ProductName, products.Category });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM