Member_2_7967608
asked on
Linq Query Add new object array
Hi
I had question on this Refactor C# code.
How do I query this if we have more than Single record for SalesOrderType(Mapping SubDocuments.Attributes) sepertaed by "$,$"
E.g. if we have document.attributes[0 ].value as below
Note we have 2 records in this separated by $,$
1**10**New Client**2016-11-02**250**1 0-F0040Z$$ 10-F0040Z$ $10-F00141 $,$1W**New Client - Add2 Product**2016-11-02**250** 1W-F71900$ $1W-F0070X
req.salesOrders = (from document in resp.transaction.quote_dat a.sub_docu ments
let values = document.attributes[0].val ue.ToStrin g().Split( new[] { "**" }, StringSplitOptions.None)
where (document.attributes != null && document.attributes.Length > 0) && !string.IsNullOrWhiteSpace (document. attributes [0].value. ToString() ) && !string.IsNullOrEmpty(valu es[3]) && (!string.IsNullOrWhiteSpac e(values[5 ]) && values[5] != "$$")
select new salesOrder()
{
productCode = values[1],
salesOrderType = values[2],
startDate = DateTime.Parse(values[3]). ToString(" yyyy-MM-dd "),
pays = !string.IsNullOrWhiteSpace (values[4] ) ? int.Parse(values[4]) : 0,
scns = (from code in values[5].Split(new[] { "$$" }, StringSplitOptions.RemoveE mptyEntrie s)
select
new scns()
{
scnCode = code
}).GroupBy(o => o.scnCode).Select(g => g.First()).ToList()
}).ToList() ;
I had question on this Refactor C# code.
How do I query this if we have more than Single record for SalesOrderType(Mapping SubDocuments.Attributes) sepertaed by "$,$"
E.g. if we have document.attributes[0 ].value as below
Note we have 2 records in this separated by $,$
1**10**New Client**2016-11-02**250**1
req.salesOrders = (from document in resp.transaction.quote_dat
let values = document.attributes[0].val
where (document.attributes != null && document.attributes.Length
select new salesOrder()
{
productCode = values[1],
salesOrderType = values[2],
startDate = DateTime.Parse(values[3]).
pays = !string.IsNullOrWhiteSpace
scns = (from code in values[5].Split(new[] { "$$" }, StringSplitOptions.RemoveE
select
new scns()
{
scnCode = code
}).GroupBy(o => o.scnCode).Select(g => g.First()).ToList()
}).ToList() ;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, take a close look at the results I posted you will see each input line gets split into two records for each line.
ASKER
There is case where a row does not have '$,$'. Will it query this record.
1**99**New Client**2016-11-02**250**1 0-F0040Z$$ 10-F0040Z$ $10-F00141
1**99**New Client**2016-11-02**250**1
A single record in one string worked for me, I used this as input.
string[] documents = {"1**10**New Client**2016-11-02**250**10-F0040Z$$10-F0040Z$$10-F00141" };
ASKER
Thanks Fernando.
ASKER
Thanks Fernando, One thing I needed was to eliminate duplicates in the output list req.salesOrders for salesOrder.productCode
Example req.salesOrders should have single record for req.salesOrders=10 (product) this should be unique. All the req.scns
> 1**10**New Client**2016-11-02**250**F 0040Z$$F00 40Z$$F0014 1$,$1**,1W **New Client - Add2 Product**2016-11-02**250** F71900$$F0 070X
> 1**10**New Client**2016-11-02**250**F 00498$$F00 493$$F0014 1
Example in above it should return
{
productCode = 10
salesOrderType =New Client,
startDate = '2016-11-02',
pays = 250
scns = {F0040Z,F00141, F00498,F00493} //removed dups . this is implemented
}
{
productCode = 1W
salesOrderType =New Client - Add2 Product,
startDate = '2016-11-02',
pays = 250
scns = { F71900,F0070X}
}
The DTOs of this question are in the link below. I was not sure if we can implement in the same link.
https://www.experts-exchange.com/questions/28958730/Refactor-C-code.html
Example req.salesOrders should have single record for req.salesOrders=10 (product) this should be unique. All the req.scns
> 1**10**New Client**2016-11-02**250**F
> 1**10**New Client**2016-11-02**250**F
Example in above it should return
{
productCode = 10
salesOrderType =New Client,
startDate = '2016-11-02',
pays = 250
scns = {F0040Z,F00141, F00498,F00493} //removed dups . this is implemented
}
{
productCode = 1W
salesOrderType =New Client - Add2 Product,
startDate = '2016-11-02',
pays = 250
scns = { F71900,F0070X}
}
The DTOs of this question are in the link below. I was not sure if we can implement in the same link.
https://www.experts-exchange.com/questions/28958730/Refactor-C-code.html
Hi;
A couple of things. First EE likes only to have one question per thread with followup questions relating to the original question posted. Because your last post does not relate to the original question please open a new question for it and I will be happy to look at it. Secondly what do you mean by duplicates? For example in req.salesOrders you have five fields, do ALL fields of a record have to be exactly the same or only some or one fields be the same for it to be a duplicate?
A couple of things. First EE likes only to have one question per thread with followup questions relating to the original question posted. Because your last post does not relate to the original question please open a new question for it and I will be happy to look at it. Secondly what do you mean by duplicates? For example in req.salesOrders you have five fields, do ALL fields of a record have to be exactly the same or only some or one fields be the same for it to be a duplicate?
ASKER
Sorry about it , I was not aware about it. I put it since it was very much related. I can open new question if u want to.
In the output list req.saleorders we have remove duplicates by productCode.
In the below example it is value[1] 10, 1W.
req.salesorders should be unique on the value[1] field
> 1**10**New Client**2016-11-02**250**F 0040Z$$F00 40Z$$F0014 1$,$1**,1W **New Client - Add2 Product**2016-11-02**250** F71900$$F0 070X
> 1**10**New Client**2016-11-02**250**F 00498$$F00 493$$F0014 1
Thanks in advance
In the output list req.saleorders we have remove duplicates by productCode.
In the below example it is value[1] 10, 1W.
req.salesorders should be unique on the value[1] field
> 1**10**New Client**2016-11-02**250**F
> 1**10**New Client**2016-11-02**250**F
Thanks in advance
Yes, please open a new question. Thank you.
ASKER
1**10**New Client**2016-11-02**250**1
the second row can be as below with no $,$
1**99**New Client**2016-11-02**250**1