c# - Type of one of the expressions in the join clause is incorrect -


i´m learning linq , trying use cross join error: type of 1 of expressions in join clause incorrect

isn´t possible use getcategories() in cross join? request in main functions outside of it.

var q = c in getcategories()         join p in getproducts() on c equals p.categoryid         c.name = "beverages"         select new { id = c, p.name }; 

method signatures:

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 } ); 

you need specify field in category class join on.. id:

from c in getcategories() join p in getproducts() on c.id equals p.categoryid c.name == "beverages" select new { id = c.id, p.name }; 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -