views:

132

answers:

2

I am in the process building myself a simple Linq to SQL repository pattern.

What I wanted to know is, is it possible to set a default sort column so I don't have to call orderby. From what I have read I don't think it is and if this is the case what would recommend for a solution to this problem.

Would the best idea be to use an attribute on a partial class on my model?

+4  A: 

the default order is the clustered index on the table you are pulling from.

What are you wanting to sort on (without sorting on) ?

Saint Gerbil
A: 

If you needed something other than having it sorted by the primary key, you could look at supplying a select statement for the table instead of using the runtime generated statement. Look at the properties on the table in the designer -- you should be able to override the runtime generated select, delete, and update statements. I don't personally recommend this, though, since I'm not sure how it will interact with other orderings. I think the intent is more along the lines of allowing you to use stored procedures if you want.

Another alternative would be to create a table-valued function or stored procedure that does the ordering the way you want and has the same schema as the table. If, in the designer, you drag this onto the table, you get a strongly typed method on the data context that you can use to obtain those entities according to the definition of the function/procedure instead of the standard select. Personally I think this introduces fewer maintenance headaches because it makes it more visible, but you do have to remember to use the method instead of the Table property for that entity.

tvanfosson