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

The Index.SaveObject(pocoModel) dont work when ObjectId is in baseclass of POCO #536

Closed
alexdoan102 opened this issue Feb 9, 2019 · 2 comments
Assignees
Labels

Comments

@alexdoan102
Copy link

The Index.SaveObject(pocoModel) dont work when ObjectId is in baseclass of POCO.
==> You get error: The type {nameof(T)} must have an ObjectID property or a JsonPropertyAttribute with name='objectID.

The issue is your AlgoliaHelper.PropertyOrJsonAttributeExists() function is wrong.
The reflection it uses to check for public properties is incorrect/wrong:

var typeInfo = typeof(T).GetTypeInfo();
var declaredProperties = typeInfo.DeclaredProperties; <=== !!!! this is wrong. !!!!!!!!

the DeclaredProperties will not retrieve the baseclass properties.
==> this is why it is not seeing ObjectID ==> because ObjectID is in base class.

The fix is to use this code:

var declaredProperties = typeof(T).GetProperties();

==> this will give you all the public properties (even the one in the base class..)

Please apply this fix asap. We are trying to use your 6.0.0 version in production as soon as possible.
Thank you.

@Ant-hem Ant-hem added the Bug label Feb 9, 2019
@Ant-hem Ant-hem self-assigned this Feb 9, 2019
@Ant-hem
Copy link
Member

Ant-hem commented Feb 11, 2019

Hey!

Thanks for your contribution, it's a good catch.

We didn't use typeof(T).GetProperties(); because we are supporting .NET Standard 1.0 and this method is not available in this one. However, you're right that DeclaredProperties isn't retrieving properties of the base class. Hopefully, there is a way to retrieve the base class properties with DeclaredProperties. I'll submit a PR today with the fix and I'll ship a fix with 6.0.1 in a few days.

@Ant-hem
Copy link
Member

Ant-hem commented Feb 11, 2019

Solved with 6.0.1

@Ant-hem Ant-hem closed this as completed Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants