Views: 7.2K
Replies: 1
Archived
|
Sorting with stored proceduresIn the example for sql server they use inline statements and pass in the sortexpression and add it in the statement. If you are using stored procedures how do you use the passed in sortexpression for sorting the grid? the sortexpression being passed in may look like "weight asc" as you may know.
I do see you can add an .Orderby at the end of the return on the Db.Readlist but I'm not sure how that works. Thanks Dennis public List<Audit> GetAudits(int id, string type, string code, string sortExpression) { string proc = @"usr_StoredProc"; object[] parms = {"@type", type, "@id", id, "@code", code}; return Db.ReadList(proc, Make, parms); } Dennis Tucker, Mar 29, 2012
|
|
Reply 1Hi Dennis,
I'm not totally sure on this one, as I don't have more details about the Db-object, but I assume it's just a DataContext. In that case queries like e.g. ReadList() return an IEnumerable<T>. That means a OrderBy-statement after ReadList(proc, Make, parms) would just adjust your actual query string for a db-query (when it is actually done). An example for a OrderBy is include in the sample-sourcecode below. Regards Florian public class Contact { int Id = 0; string Name = string.Empty; } var result = Db.ReadList(proc, Make, parms) .Cast<Contact>() .OrderBy(x => x.Name) // add order statements to query .ToList(); // execute actual query Florian Schaeffler, Apr 03, 2012
|