List:Commits« Previous MessageNext Message »
From:Julio Casal Date:June 9 2011 1:24pm
Subject:bzr commit into connector-net-6.1 branch (julio.casal:896) Bug#46742
Bug#12622129
View as plain text  
#At file:///D:/Users/jcasalt/Dev/connector-net/features/Bug46742/ based on revid:julio.casal@stripped4745-dyqu1xnye5pzi0a7

  896 Julio Casal	2011-06-09
      Fixed Entity Framework provider GROUP BY clause generation by adding all group by keys to the SELECT statement (MySQL bug #46742, Oracle bug #12622129).

    modified:
      CHANGES
      MySql.Data.Entity/Provider/Generators/SelectGenerator.cs
      MySql.Data.Entity/Tests/OrderingAndGrouping.cs
      MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs
      MySql.Data.Entity/Tests/Properties/SQLSyntax.resx
=== modified file 'CHANGES'
--- a/CHANGES	2011-06-02 17:47:45 +0000
+++ b/CHANGES	2011-06-09 13:24:33 +0000
@@ -49,6 +49,7 @@
 - Modified Connection.Open() to not reuse existing driver instance when that instance is closed. Also made Connection.Abort() 
   always close the current driver, even if the connection is pooled. (MySQL bug #58316, Oracle bug #12613102).
 - Added Visual Studio DDEX support for Compact Framework projects (MySQL bug #54607, Oracle bug #12605152).
+- Fixed Entity Framework provider GROUP BY clause generation by adding all group by keys to the SELECT statement (MySQL bug #46742, Oracle bug #12622129).
 
 Version 6.1.5
 - Fix authorization popup after modifying stored procedure in VS (Bug #44715)

=== modified file 'MySql.Data.Entity/Provider/Generators/SelectGenerator.cs'
--- a/MySql.Data.Entity/Provider/Generators/SelectGenerator.cs	2011-04-20 18:39:38 +0000
+++ b/MySql.Data.Entity/Provider/Generators/SelectGenerator.cs	2011-06-09 13:24:33 +0000
@@ -91,10 +91,21 @@ namespace MySql.Data.Entity
             RowType rt = (RowType)ct.TypeUsage.EdmType;
 
             int propIndex = 0;
+
             foreach (DbExpression key in expression.Keys)
             {
-                select.AddGroupBy(key.Accept(this));
+                var fragment = key.Accept(this);
+                select.AddGroupBy(fragment);
                 propIndex++;
+
+                var colFragment = fragment as ColumnFragment;
+
+                if (colFragment != null)
+                {
+                    colFragment = colFragment.Clone();
+                    colFragment.ColumnAlias = String.Format("K{0}", propIndex);
+                    select.Columns.Add(colFragment);
+                }        
             }
 
             for (int agg = 0; agg < expression.Aggregates.Count; agg++)

=== modified file 'MySql.Data.Entity/Tests/OrderingAndGrouping.cs'
--- a/MySql.Data.Entity/Tests/OrderingAndGrouping.cs	2011-03-03 17:57:57 +0000
+++ b/MySql.Data.Entity/Tests/OrderingAndGrouping.cs	2011-06-09 13:24:33 +0000
@@ -30,6 +30,7 @@ using System.Data.Common;
 using NUnit.Framework;
 using System.Data.Objects;
 using MySql.Data.Entity.Tests.Properties;
+using System.Linq;
 
 namespace MySql.Data.Entity.Tests
 {
@@ -83,5 +84,66 @@ namespace MySql.Data.Entity.Tests
                 }
             }
         }
+
+        [Test]
+        public void CanGroupBySingleColumn()
+        {
+            MySqlDataAdapter adapter = new MySqlDataAdapter(
+                "SELECT Name, COUNT(Id) as Count FROM Companies GROUP BY Name", conn);
+            DataTable table = new DataTable();
+            adapter.Fill(table);
+
+            using (testEntities context = new testEntities())
+            {
+                var companies = from c in context.Companies
+                                group c by c.Name into cgroup
+                                select new 
+                                { 
+                                    Name = cgroup.Key, 
+                                    Count = cgroup.Count() 
+                                };
+                string sql = companies.ToTraceString();
+                CheckSql(sql, SQLSyntax.CanGroupBySingleColumn);
+
+                int i = 0;
+                foreach (var company in companies)
+                {
+                    Assert.AreEqual(table.Rows[i][0], company.Name);
+                    Assert.AreEqual(table.Rows[i][1], company.Count);
+                    i++;
+                }
+            }
+        }
+
+        [Test]
+        public void CanGroupByMultipleColumns()
+        {
+            MySqlDataAdapter adapter = new MySqlDataAdapter(
+                "SELECT Name, COUNT(Id) as Count FROM Companies GROUP BY Name, NumEmployees, DateBegan", conn);
+            DataTable table = new DataTable();
+            adapter.Fill(table);
+
+            using (testEntities context = new testEntities())
+            {
+                var companies = from c in context.Companies
+                                group c by new { c.Name, c.NumEmployees, c.DateBegan } into cgroup
+                                select new
+                                {
+                                    Name = cgroup.Key.Name,
+                                    Count = cgroup.Count()
+                                };
+
+                string sql = companies.ToTraceString();
+                CheckSql(sql, SQLSyntax.CanGroupByMultipleColumns);
+
+                int i = 0;
+                foreach (var company in companies)
+                {
+                    Assert.AreEqual(table.Rows[i][0], company.Name);
+                    Assert.AreEqual(table.Rows[i][1], company.Count);
+                    i++;
+                }
+            }
+        }
     }
 }
\ No newline at end of file

=== modified file 'MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs'
--- a/MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs	2011-05-25 03:37:35 +0000
+++ b/MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs	2011-06-09 13:24:33 +0000
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:2.0.50727.4959
+//     Runtime Version:2.0.50727.5444
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -134,6 +134,46 @@ namespace MySql.Data.Entity.Tests.Proper
         
         /// <summary>
         ///   Looks up a localized string similar to SELECT
+        ///1 AS C1, 
+        ///GroupBy1.K1 AS Name, 
+        ///GroupBy1.A1 AS C2
+        ///FROM (SELECT
+        ///Extent1.Name AS K1, 
+        ///Extent1.DateBegan AS K2, 
+        ///Extent1.NumEmployees AS K3, 
+        ///COUNT(1) AS A1
+        ///FROM Companies AS Extent1
+        /// GROUP BY 
+        ///Extent1.Name, 
+        ///Extent1.DateBegan, 
+        ///Extent1.NumEmployees) AS GroupBy1.
+        /// </summary>
+        internal static string CanGroupByMultipleColumns {
+            get {
+                return ResourceManager.GetString("CanGroupByMultipleColumns", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to SELECT
+        ///1 AS C1, 
+        ///GroupBy1.K1 AS Name, 
+        ///GroupBy1.A1 AS C2
+        ///FROM (SELECT
+        ///Extent1.Name AS K1, 
+        ///COUNT(1) AS A1
+        ///FROM Companies AS Extent1
+        /// GROUP BY 
+        ///Extent1.Name) AS GroupBy1.
+        /// </summary>
+        internal static string CanGroupBySingleColumn {
+            get {
+                return ResourceManager.GetString("CanGroupBySingleColumn", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to SELECT
         ///GroupBy1.A1 AS C1
         ///FROM (SELECT
         ///Count(Extent1.Id) AS A1

=== modified file 'MySql.Data.Entity/Tests/Properties/SQLSyntax.resx'
--- a/MySql.Data.Entity/Tests/Properties/SQLSyntax.resx	2011-05-25 03:37:35 +0000
+++ b/MySql.Data.Entity/Tests/Properties/SQLSyntax.resx	2011-06-09 13:24:33 +0000
@@ -159,6 +159,34 @@ FROM (SELECT
 Count(Extent1.Id) AS A1
 FROM Toys AS Extent1) AS GroupBy1</value>
   </data>
+  <data name="CanGroupByMultipleColumns" xml:space="preserve">
+    <value>SELECT
+1 AS C1, 
+GroupBy1.K1 AS Name, 
+GroupBy1.A1 AS C2
+FROM (SELECT
+Extent1.Name AS K1, 
+Extent1.DateBegan AS K2, 
+Extent1.NumEmployees AS K3, 
+COUNT(1) AS A1
+FROM Companies AS Extent1
+ GROUP BY 
+Extent1.Name, 
+Extent1.DateBegan, 
+Extent1.NumEmployees) AS GroupBy1</value>
+  </data>
+  <data name="CanGroupBySingleColumn" xml:space="preserve">
+    <value>SELECT
+1 AS C1, 
+GroupBy1.K1 AS Name, 
+GroupBy1.A1 AS C2
+FROM (SELECT
+Extent1.Name AS K1, 
+COUNT(1) AS A1
+FROM Companies AS Extent1
+ GROUP BY 
+Extent1.Name) AS GroupBy1</value>
+  </data>
   <data name="CountSimple" xml:space="preserve">
     <value>SELECT
 GroupBy1.A1 AS C1

Attachment: [text/bzr-bundle] bzr/julio.casal@oracle.com-20110609132433-fzvm9ubcw8fggh9o.bundle
Thread
bzr commit into connector-net-6.1 branch (julio.casal:896) Bug#46742Bug#12622129Julio Casal9 Jun