0

Morning all

Now I know there is a reason to this odering but my tiny little brain can't get my head around it.

I am using a webservice to pull through data to a webp[age and have the following that is so far pulling data through from UUF1:

 public string[] GetBuyer(string Memberkey) { try { WebService.EntitiesConnection buyer = new WebService.EntitiesConnection(); return buyer.tblProducts .Where(p => p.MemberId == Memberkey) .OrderBy(p => p.UnitUserfield1) .Select(p => p.UnitUserfield1) .Distinct() .ToArray(); } catch (Exception) { return null; } } 

This works fine and pulls the data through but in a strange order. Where I would expect results of A B C D E F, it appears to be returning A C E B D F.

Could someone point out the error in my ways please?

2 Answers 2

1

Do your OrderBy last, i have seen this before with LinqToSql, having the OrderBy before the Distinct caused it to generate SQL with no OrderBy in it.

Sign up to request clarification or add additional context in comments.

3 Comments

I have tried that but when implementing this, I receive " 'string' does not contain a definition for 'UnitUserfield1' and no extension method 'Unitiuserfield1' accepting a first argument of type 'string' could be found" error. I'm not sure how to tackle that bad boy.
Your dealing with an IEnumerable<string> collection by then so just do .OrderBy(p => p);
Top, top man...thank you Ben. For anyone wanting the final code: return buyer.tblProducts .Where(p => p.MemberId == Memberkey) .Select(p => p.UnitUserfield1) .Distinct() .OrderBy(p => p) .ToArray();
0

Top, top man...thank you Ben. For anyone wanting the final code:

 return buyer.tblProducts .Where(p => p.MemberId == Memberkey) .Select(p => p.UnitUserfield1) .Distinct() .OrderBy(p => p) .ToArray();` 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.