【发布时间】:2014-04-14 02:33:42
【问题描述】:
我正在学习 LINQ 并尝试使用交叉连接我收到此错误:连接子句中的表达式之一的类型不正确
在 Cross Join 中不能使用 GetCategories() 吗?此请求在 main 中,但在它之外。
var q = from c in GetCategories()
join p in GetProducts() on c equals p.CategoryID
where c.Name = "Beverages"
select new { ID = c, p.Name };
方法签名:
public static IEnumerable<Category> GetCategories()
List<Category> categories = new List<Category>( );
categories.Add( new Category { ID = 1, Name = "Beverages" } );
public static IEnumerable<Product> GetProducts()
List<Product> products = new List<Product>( );
products.Add( new Product { Name = "Milk", Price = 90, CategoryID = 4, ID = 1 } );
【问题讨论】:
-
你的方法的返回类型是什么