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

Projection doesnt work with concrete types #64

Open
zulkamal opened this issue Mar 22, 2011 · 1 comment
Open

Projection doesnt work with concrete types #64

zulkamal opened this issue Mar 22, 2011 · 1 comment

Comments

@zulkamal
Copy link

Profiling mongo when running projected queries show that the reslen and bytes returned are the same as non projected queries.

Applies to both standard and linq queries.

@zulkamal
Copy link
Author

I believe I've found the problem area but unfortunately I don't know how to fix it (not familiar with linq. yet!)

In MongoCollectionGeneric.cs - line 385
public IEnumerable Find<U, O, Z>(U template, O orderBy, int limit, int skip, String fullName, Expression<Func<T, Z>> fieldSelection)

For anonymous lambdas, the fieldSelection cast goes well but for concrete-typed lambdas, none of casts go through cause the expression in now a MemberInitExpression, so fieldSelectionExpando never gets populated.

#region Extract field names to request
        var exp = fieldSelection.Body as NewExpression;
        var fieldSelectionExpando = new Expando();
        if (exp != null)
        {
            foreach (var x in exp.Arguments.OfType<MemberExpression>())
            {
                fieldSelectionExpando[x.GetPropertyAlias()] = 1;
            }
        }
        else if (fieldSelection.Body is MemberExpression)
        {
            var me = fieldSelection.Body as MemberExpression;
            fieldSelectionExpando[me.GetPropertyAlias()] = 1;
        }
#endregion

Hope this helps.

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