Linq To SQL: Sort Query by Arbitrary Property(Column) Name

后端 未结 3 1644
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 12:42

I have a larger/more complex problem, but for simplicity sake, let us consider the following:

Let us say that I have table in the SQL DataBase calle

3条回答
  •  无人及你
    2021-01-11 13:15

    It is not as easy as it seems. The LINQ to SQL engine parses the expression you pass to the OrderBy method in order to obtain the name of the property you are referencing, then uses this information to compose a plain SQL order by clause.

    I guess that maybe it can be done by using reflection, anyway. Maybe you can get something useful from the accepted answer of this SO question.

提交回复
热议问题