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

Research: replace AnonType with Tuples? #254

Closed
3 of 4 tasks
AlekseyMartynov opened this issue Jun 1, 2018 · 1 comment
Closed
3 of 4 tasks

Research: replace AnonType with Tuples? #254

AlekseyMartynov opened this issue Jun 1, 2018 · 1 comment
Assignees

Comments

@AlekseyMartynov
Copy link
Contributor

AlekseyMartynov commented Jun 1, 2018

var q = new Model1().Products.Select(p => new {
    Item1 = p.ProductID,
    Item2 = new {
        Item1 = p.ProductName
    }
});

can be built as

var p = Expression.Parameter(typeof(Product));

var t1 = typeof(Tuple<int, Tuple<string>>);
var t2 = typeof(Tuple<string>);

var q = new Model1().Products.Select(
    Expression.Lambda<Func<Product, Tuple<int, Tuple<string>>>>(
        Expression.New(
            t1.GetConstructor(new[] { typeof(int), t2 }),
            new Expression[] {
                Expression.Property(p, "ProductID"),

                Expression.New(
                    t2.GetConstructor(new[] { typeof(string) }),
                    new Expression[] {
                        Expression.Property(p, "ProductName")
                    },
                    t2.GetProperty("Item1")
                )

            },
            t1.GetProperty("Item1"),
            t1.GetProperty("Item2")
        ),
        p
    )
);

TODO check compatibility:

  • EF (ok >= 4.3)
  • EF Core (ok 1.0.6, 2.1.0)
  • XPO (18.1.3 Select ok, GroupBy fails, fix requested)
  • NHibernate (ok 5.1)
@AlekseyMartynov AlekseyMartynov self-assigned this Jun 1, 2018
@AlekseyMartynov
Copy link
Contributor Author

Code: https://github.com/DevExpress/DevExtreme.AspNet.Data/tree/experiment/tuples

Pros:

  • No need for custom types (AnonType)
  • Unlimited length

Cons:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant