You can probably add such pre-SQL optimizations to DbLinq.Data.Linq.Sugar.Implementation.PrequelAnalyzer.This class is (poorly at the moment) used to change expressions before the SQL generation. This is the place where you could remove an OrderBy expression if it precedes a Count, in the case of specific databases (with information added to ISqlProvider). But this probably won't be obvious, since it probably requires a lot of preliminary changes, such as: - ISqlProvider to tell if it likes special things such as ordered counts - Expression analysis, to understand that we're using an order before a count (and all possible variants).
I know it probably doesn't help much more, but I still hope it does "unhelp" less :) On Wed, May 6, 2009 at 15:16, Jonathan Pryor <[email protected]> wrote: > Sorry to ask the obvious, but where is Expression optimization done? Any > types/methods to refer me to? > > Thanks, > - Jon > > > On Wed, 2009-05-06 at 14:14 +0200, Pascal Craponne wrote: > > This could probably be done during Expression optimization, then. I suggest > adding some features to IVendor or ISqlProvider. > > (my suggestions may become less accurate, since I haven't working on > DbLinq code for a while) > > On Wed, May 6, 2009 at 14:03, Jonathan Pryor <[email protected]> wrote: > > I expect no 'ORDER BY' in that case, i.e. 'SELECT COUNT(*) FROM [people]' > (as that doesn't generate an error). (Alternatively, find some other > formulation so that SQL Server doesn't reject the 'ORDER BY', but I > haven't been able to find such a formulation.) > > - Jon > > > > > On Wed, 2009-05-06 at 09:43 +0200, Pascal Craponne wrote: > > What SQL statement do you expect in such a case? > > On Wed, May 6, 2009 at 06:25, Jonathan Pryor <[email protected]> wrote: > > How is the SQL generated for the .Count() extension method? > > The current bug I'm seeing is that for the C# code: > > int count = > (from p in Context.GetTable<Person>() > orderby p.LastName > select p) > .Count(); > > the following SQL is generated for Microsoft SQL Server: > > SELECT COUNT(*) > FROM [people] > ORDER BY [last_name] > > SQL Server doesn't like this SQL because of the 'ORDER BY' clause. After > a slightly more than cursory perusal, I'm not sure why the 'ORDER BY' is > being generated here, nor am I sure how to fix this. > > Thoughts? > - Jon > > > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DbLinq" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dblinq?hl=en -~----------~----~----~----~------~----~------~--~---
