user3118955
user3118955

Reputation: 41

Is there any way to use OData $orderby on complex type?

Example:

public class Address 
{
   public string Address1 {get; set;}
   public string Address2 {get; set;}
}

public class User
{
   public int Id{get; set;}
   //Complex type
   public Address Address{get; set;}
}

I have a grid that is fill with data of User. I want to make $orderby by Address, is this posible?

Upvotes: 2

Views: 247

Answers (1)

Christoph Brückmann
Christoph Brückmann

Reputation: 1373

Maybe you should use the List object:

public class AddressObject
{
   public string Address {get; set;}
}

public class User
{
   public int Id {get; set;}

   public List<AddressObject> adressList = new List<AddressObject>();
}

Than you can order with LINQ:

var orderedAdressList = adressList.OrderBy(z => z.Address)

Upvotes: 1

Related Questions