How can I sort my IList<Customer> Customers by LastName?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
I've got a list of customers for my plugin, how can I sort that list by LastName?

I tried getting it by

sorted = _customers.ToList().OrderBy(c => c.Addresses.First().LastName);

But I got errors saying that it didn't exist.

I saw another post, saying something about GetAttribute, but when I try that it says that method doesn't exist... and it doesn't show up in my intellisense either.

Help!?
11 years ago
jwwelbor wrote:
I've got a list of customers for my plugin, how can I sort that list by LastName?

I tried getting it by

sorted = _customers.ToList().OrderBy(c => c.Addresses.First().LastName);

But I got errors saying that it didn't exist.

I saw another post, saying something about GetAttribute, but when I try that it says that method doesn't exist... and it doesn't show up in my intellisense either.

Help!?


Why are you sorting based on the addresses? You can do something like
_customers.OrderBy(c => c.GetAttribute<string>(SystemCustomerAttributeNames.FirstName))
. The GetAttribute method is an extension method resides in Nop.Services.Common, so you have to include this namespace. Nop way of storing generic information of entities is by using the Attribute systems, so that you can easily add new attributes to a customized system. Properties like FirstName and LastName, are such examples. That's why you cannot directly access these properties as they are stored as attribute and not Property. :)
11 years ago
Ahhh.... that's it.  I searched for it, and it looked like it was under Nop.Services I missed the Nop.Services.Common.

Woon Cherk to the rescue again!!  Thanks Buddy.
11 years ago
Hehe. No problem. :P
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.