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

GroupBy clause add an "Item" property when projects the query #75

Closed
jotab123 opened this issue Apr 17, 2017 · 6 comments
Closed

GroupBy clause add an "Item" property when projects the query #75

jotab123 opened this issue Apr 17, 2017 · 6 comments
Assignees

Comments

@jotab123
Copy link
Contributor

jotab123 commented Apr 17, 2017

Hi Stef,

GroupBy is adding an "extra" property called "Item" when I create a grouped query and projects it with Select.

//elements is a List<Element> where Element is a simple Class with a public int PropertyKey property generated
// with 0 or 1 value in a routine. 

var dynamicResult = elements.AsQueryable().GroupBy("PropertyKey").Select("new (it.key as PropertyKey)");
var result = elements.GroupBy(e => e.PropertyKey).Select(e => new { PropertyKey = e.Key}).AsQueryable();

//I think this should be true, but it isn't. dynamicResult add System.Object Item [System.String] property.
dynamicResult.ElementType.GetProperties().Count() == result.ElementType.GetProperties().Count()

Linq.Dynamic.Core 1.0.6.13

@jotab123
Copy link
Contributor Author

I was trying in previous versions and works fine in 1.0.6.9. Doesn't work from 1.0.6.10.

@StefH
Copy link
Collaborator

StefH commented Apr 18, 2017

This change is indeed introduced when I added Add [] to DynamicClass functionality.

If you need all property names, use https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/DynamicClass.cs#L282

@jotab123
Copy link
Contributor Author

Ok, thanks! but, what is Item property? If I try to get the value throws an exception.

@StefH
Copy link
Collaborator

StefH commented Apr 18, 2017

I think that when you use the same rules for getting the valid properties like https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/DynamicClass.cs#L188, all will work fine.

Or do you have a specific scenario?

@jotab123
Copy link
Contributor Author

jotab123 commented Apr 18, 2017

Using the previous example, If I try to get the value of property throws a System.Reflection.TargetParameterCountException.

var property = dynamicResult.ElementType.GetProperty("Item");
var value = property.GetValue(dynamicResult.First());

@StefH StefH self-assigned this Apr 18, 2017
StefH added a commit that referenced this issue Apr 18, 2017
@StefH
Copy link
Collaborator

StefH commented Apr 18, 2017

The Item property is an indexer, so you can't use this as a normal property.

See Q+A here;
http://stackoverflow.com/questions/291359/c-sharp-reflection-indexed-properties

@StefH StefH closed this as completed Apr 18, 2017
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

2 participants