OK for me, this looks just fine. On Thu, May 7, 2009 at 17:13, Jonathan Pryor <[email protected]> wrote:
> Attached is my current patch. Some minor things, but the basic approach > is there. > > The approach is to add an ExpressionTranslator type (with one current > method, OuterExpression()) which is invoked by SqlBuilder *before* the > expression is converted into a SQL string, thus allowing vendor-specific > code to manipulate the underlying expression tree (and remove the OrderBy > clauses for Count expressions under SQL Server). > > To do so, I made most of the DbLinq.Data.Linq.Sugar.Expressions.* types > public (so that the vendor code could use them). > > OK to commit? > > Side question: why the preference to interfaces over classes? FxDG > suggests preferring classes over interfaces for versioning reasons (you can > add methods to classes w/o breaking derived types, which isn't true with > interfaces). I added a GetTranslator() method to SqlProvider (and *not* > ISqlProvider) for precisely this reason, as if I were to instead change > ISqlProvider I'd have to change *every* vendor implementation, instead of > just the ones that matter. > > I'd actually prefer to just drop the ISqlProvider interface and use > SqlProvider directly. > > Thanks, > - Jon > > > On Wed, 2009-05-06 at 15:50 +0200, Pascal Craponne wrote: > > 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 -~----------~----~----~----~------~----~------~--~---
