c# - LINQ to separate column value of a row to different rows in .net -
consider have datatable retrieved oracle database in following format
sno. | product | cost ------------------------------------------------- 1 | colgate,closeup,pepsodent | 50 2 | rin,surf | 100
i need change following format using linq.need separate product column of comma keeping other columns same.
sno. | product | cost ------------------------------------- 1 | colgate | 50 1 | closeup | 50 1 | pepsodent | 50 2 | rin | 100 2 | surf | 100
please try this:
list<product> uncompressedlist = compressedproducts .selectmany(singleproduct => singleproduct.productname .split(',') .select(singleproductname => new product { sno = singleproduct.sno, productname = singleproductname, cost = singleproduct.cost })) .tolist();
edit:
product class defined follows:
public class product { public int32 sno { get; set; } public string productname { get; set; } public int32 cost { get; set; } }
and compressedproducts initial list of products first example.
Comments
Post a Comment