c# - linq join with groups -
c# - linq join with groups -
hej, i've got problem linq expression. perform bring together groups of set. basicly need:
var f = new ienumerable<someclass> { ... }; var rows = new ienumerable<someotherclass> { ... }; var makedgroups = rows.groupby(row => row.someid); var groupsjoined = (from row in makedgroups bring together allocquant in f on row.key.value equals allocquant.someid gj select gr => new { count = gr.count(), grouping = gj });
error is: error 202 type of 1 of expressions in bring together clause incorrect. type inference failed in phone call 'join'.
how write look properly?
i have included sample code doing trying do. adapted sample code utilize 2 classes rather static array of strings.
the result yield ienumerable productcategory field, products field contains groupings of products based on category , lastly column count in grouping.
from asked thought wanted.
class product { public product(string cat, string name) { category = cat; productname = name; } public string category { get; set;} public string productname { get;set;} } class productclass { public productclass (string type) { producttype = type; } public string producttype { get;set;} } productclass[] productclasses = new productclass[]{ new productclass("beverages"), new productclass("condiments"), new productclass("vegetables"), new productclass("dairy products"), new productclass("seafood") }; list<product> products = new list<product>(); products.add(new product("seafood", "crab sticks")); products.add(new product("seafood", "lobster")); products.add(new product("vegetables", "cucumber")); products.add(new product("seafood", "oysters")); products.add(new product("condiments", "pepper")); products.add(new product("condiments", "salt")); var query = pc in productclasses bring together product in products on pc.producttype equals product.category gj select new { productcategory= pc.producttype, products = gj, count = gj.count() };
c# linq
Comments
Post a Comment