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

OrderBy while loading child entities #157

Open
b9chris opened this issue Mar 17, 2016 · 0 comments
Open

OrderBy while loading child entities #157

b9chris opened this issue Mar 17, 2016 · 0 comments

Comments

@b9chris
Copy link
Contributor

b9chris commented Mar 17, 2016

This is less of an Issue and more a Discussion.

EFGraphDiff is a huge help when saving, but I've found I come up wanting when loading for a couple of reasons, and I want to focus in on the big one here: OrderBy.

EFGraphDiff doesn't use an OrderBy when loading an Entity's child Collections from the db.

  • Performance: I've found that unordered queries against Sql Server Web Edition are far slower than any query with an OrderBy that can use an Index.
  • Consistency: Many use cases and interfaces require a particular sort order.

These combine to mean EFGraphDiff's loading capabilities are in the way of the right way of loading these Entities. I've put together code that lets you declaratively mark a class with how you'd like it ordered when loading as a child of a query. I've not addressed this but it would be reasonably easy to override the declarations when you want to via a config.

I can just post it as a separate library and people can combine them if they wish, but this does seem like a blindspot for EFGraphDiff so I wonder if this or some portion of it belongs in EFGraphDiff. The work was relatively significant since it requires emitting custom classes (that act like a runtime Anonymous class) and then asking EF to fill them with custom Select statements that are the sum of many, many Lambda Expressions.

For example:

        var propColl = Expression.Property(selectParam, dbProp);
        var orderByParam = Expression.Parameter(itemType, "p");
        var orderIndexProp = itemType.GetProperty(orderedPropName);
        var orderByExp = Expression.Lambda(
            Expression.MakeMemberAccess(orderByParam, orderIndexProp),
            orderByParam
        );
        var orderedProp = Expression.Call(
            typeof(Enumerable), "OrderBy",
            new[] { itemType, typeof(int) },
            propColl,
            orderByExp
        );
        var bindSetter = Expression.Bind(runtimeProp.SetMethod, orderedProp);

Just wanted to start the discussion. If I post this as a separate library as well I'll link back here.

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

No branches or pull requests

1 participant