Categories
c# entity-framework linq sql

In LINQ to Entities, How can you order like follows?

I have a queryable of entities with a “Code” field against them

1.1.1,
1.1.2,
1.1.3,
1.1.4,
...,
1.1.10,
1.1.11

Unfortunately, When I do an .OrderBy(x=> x.Code) on the query, it returns in the following order

1.1.1,
1.1.10,
1.1.11,
1.1.2,
1.1.3,
...

How can I make it that the object list is ordered by the code field, split by the “.”s and as an integer between each part?

This is customer data, so I can’t just put a “0” in front of the 1 number ones.
Also it is any number of “.”s in this Code field.

Let me know if you require further information.