Search code examples
linq-to-sqlcastle-activerecord

Is it Possible to set a Default Order By in Linq Attribute Mappings?


I it was possible to do this in Active Record, but is this feasible with Linq to SQL?


Solution

  • You can always add a property to the data-context / entities objects in a partial class file:

    partial class MyDataContext {
        public IOrderedQueryable<Foo> FoosByName {
            get {return Foos.OrderBy(foo=>foo.Name);}
        }
    }
    

    Then any queries started from FoosByName will be pre-ordered (but still composable).