Alyanto
asked on
LINQ and recursive query
Is there any means to do recursive queries in LINQ?
For example when distinct products are unusable because the consumer need a specific class definition but the product needs to only return only one row for each unique instance of a property.
The proper output to the question as a list would be K1, K2, K3 committing the second K1 as a duplicate. Even thought all instances are different and distinct. The result only returns only the fist instance of AnalysisCode.
For example when distinct products are unusable because the consumer need a specific class definition but the product needs to only return only one row for each unique instance of a property.
///PCode-
Class Stock
{
Prop Department as String
Prop Store as String
Prop AnalysisCode as String
}
Lst = List Of {Stock}
Lst.Add(NEW (Stock(A, B, K1 ))
Lst.Add(NEW (Stock(A, B, K2 ))
Lst.Add(NEW (Stock(A, A, K1 ))
Lst.Add(NEW (Stock(B, B, K3 ))
The proper output to the question as a list would be K1, K2, K3 committing the second K1 as a duplicate. Even thought all instances are different and distinct. The result only returns only the fist instance of AnalysisCode.
ASKER
Apologies for the delay, The result should be the full class. I realised early on that I could bracket the query and use Tolist.Distinct to get a single value. I started to consider how I might have used a SQL Server CTE recursive query to do the same job; but I could not see how I could do that in LINQ. I have a few places where having this ability would improve code and performance.
ASKER
I've requested that this question be deleted for the following reason:
There has been no response in some time and the expert was unable to give an answer that solved the problem
There has been no response in some time and the expert was unable to give an answer that solved the problem
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think I asked for the question to be deleted before Giannis responded. However when I revisited it there was the correct answer.
May thanks
Giannis
May thanks
Giannis
Well, actually, because you asked for a deletion i got a notification which reminded me that i had not given the answer. Sorry for keeping you wait.
Giannis
Giannis
Do you only need AnalysisCode as an output, or the full class? If you need the full class, is there any business rule that A,B,K1 will be returned instead of A,A,K1. Do you want just one of them (like the first)?
Giannis