Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group by multiple columns? #31

Closed
jotab123 opened this issue Jun 28, 2016 · 18 comments
Closed

Group by multiple columns? #31

jotab123 opened this issue Jun 28, 2016 · 18 comments
Labels

Comments

@jotab123
Copy link
Contributor

Hi!

I'm working on group by queries on sqlserver. I'm trying to create groups with multiple columns dynamically and I don't know how I can do it.

Example:

Model

    public class Element
    {
        [Key]
        public int Id { get; set; }
        public double Attribute1 { get; set; }
        public double Attribute2 { get; set; }
    }

Queries

I need this query result:
db.Element.GroupBy(el => new { el.Attribute1, el.Attribute2 })

Dynamically:
db.Element.GroupBy("new(Attribute1, Attribute2)")...?

Is it possible?

Thank you very much!

@StefH
Copy link
Collaborator

StefH commented Jun 28, 2016

Should be indeed something like:
var groupResult2 = queryable.GroupBy("new (NumberPropertyAsKey, StringPropertyAsKey)");

See unit-test https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/test/System.Linq.Dynamic.Core.Tests/QueryableTests.GroupBy.cs

@jotab123
Copy link
Contributor Author

I think so...but, check the output.
output

@jotab123
Copy link
Contributor Author

I was doing tests with Elements in memory and It works! I'm gonna report it to EntityFramework Core team.

Great job!

@StefH
Copy link
Collaborator

StefH commented Jun 28, 2016

Which version from EntityFramework Core do you use?

@jotab123
Copy link
Contributor Author

1.0.0 Final version.
I uploaded the full project here: https://github.com/jotab123/GroupByError

@StefH
Copy link
Collaborator

StefH commented Jun 28, 2016

The tests in your example project looks valid? I'll check what's happening.

@jotab123
Copy link
Contributor Author

There are no message error, but the query database result is wrong. It should be four groups instead of ten.

 //List test.
var resultList1 = ElementsList.GroupBy(el => new { el.Attribute1, el.Attribute2 });     //CORRECT
var resultList2 = ElementsList.AsQueryable().GroupBy("new(Attribute1, Attribute2)");    //CORRECT

 //Database tests.
var resultDb1 = db.Element.GroupBy(el => new { el.Attribute1, el.Attribute2 });         //CORRECT
var resultDb2 = db.Element.GroupBy("new(Attribute1, Attribute2)");                      //WRONG

Thank you!

@StefH
Copy link
Collaborator

StefH commented Jun 28, 2016

The "resultDb2" is indeed wrong, but I wonder if this is a problem with 'EntityFramework Core', it looks more an issue for System.Linq.Dynamic.Core ?

@jotab123
Copy link
Contributor Author

I'm not sure where the problem is, sorry. Would be great if you could check your extension method!

@StefH
Copy link
Collaborator

StefH commented Jun 29, 2016

I'll take a look.

@StefH StefH added the bug label Jun 29, 2016
@StefH
Copy link
Collaborator

StefH commented Jun 29, 2016

For the old (6.1.3) EF, it works fine. (I did add a test project)

StefH added a commit that referenced this issue Sep 27, 2016
And update to Microsoft.EntityFrameworkCore 1.0.1
Linked to #31
@StefH
Copy link
Collaborator

StefH commented Sep 27, 2016

@jotab123 I tested with EF Core 1.0.1 and it still does not work, even introduced other issue, see
dotnet/efcore#6620

@jogibear9988
Copy link
Contributor

it's fixed in ef now so can be closed?

@StefH
Copy link
Collaborator

StefH commented Nov 6, 2016

It's fixed in the 1.1 preview version. I made a new branch in this project to test it.

However, best to keep this issue open until the final EF Core 1.1 is published.

@StefH
Copy link
Collaborator

StefH commented Nov 8, 2016

Tested successfully for 1.1 preview.

@jotab123
Copy link
Contributor Author

jotab123 commented Nov 8, 2016

Great!

@jotab123 jotab123 closed this as completed Nov 8, 2016
@StefH
Copy link
Collaborator

StefH commented Nov 9, 2016

However, best to keep this issue open until the final EF Core 1.1 is published.

@StefH StefH reopened this Nov 9, 2016
@StefH
Copy link
Collaborator

StefH commented Nov 16, 2016

@StefH StefH closed this as completed Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants