From SOAP api (wsdl) I am getting list with results of Ids and quantity like this:
[0] Id: "000123-12B024", Qty: "20"
[1] Id: "000123-12B025", Qty: "30"
Etc... Where both returned results are string, Id and Qty.
Now I whant to Id parse into first six signs (to sign "-") and group Id and sum qty. So result from example would be:
[0] Id: "000123", Qty: "50" Etc
My code is:
var res = _listOfProductIdAndStock.Where(ids => ids.product_sku.Contains(@"-"))
.Select(ids => new { id = ids.product_sku.Split(Convert.ToChar("-"))[0], ids.qty })
/*To here code is fine, so my results is like:
* [0] Id: "000123", Qty: "20"
* [1] Id: "000123", Qty: "30"
* Next I whant to group it by "Id" and sum "qty" field which is string
*/
.GroupBy(ids => ids.id)
.Select(ids => new {ids.FirstOrDefault().id, ids.Sum(a => a.qty)})
// Here I get error in ids.Sum that I cannot convert expression type string to return type ('decimal,int,float etc.)
.ToList();
I don't know how to convert it, or cast it probably