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

Can not create a criteria query with return type of Hashtable #2051

Closed
futurify-ydang opened this issue Mar 12, 2019 · 3 comments
Closed

Can not create a criteria query with return type of Hashtable #2051

futurify-ydang opened this issue Mar 12, 2019 · 3 comments

Comments

@futurify-ydang
Copy link

Before upgrade to NHibernate 5.2.4 i could create a criteria query as following in NHibernate 5.1.1

var list =  _session.CreateCriteria(nameof(Setting))
               .Add(Restrictions.Eq(nameof(_settingColumnName.Key), key))
                .List<Hashtable>();

But i faced the exeption when upgrade to NHibernate 5.2.4
System.ArgumentException: The value "NHibernate.Util.DynamicComponent" is not of type "System.Collections.Hashtable" and cannot be used in this generic collection. Parameter name: value
What is wrong thing here? Please give me a help
Regards,

@bahusoid
Copy link
Member

bahusoid commented Mar 12, 2019

No sure why it's changed and when. But use instead IDictionary or IDictionary<string, object>. It should work.
Also it's documented pretty clear in possible breaking changes which I suggest your to inspect before upgrade:

* Mapping a dynamic component with a Hashtable property instead of an
IDictionary is no more supported.
* Querying a dynamic entity as a Hashtable instead of an IDictionary is no more
supported.

@fredericDelaporte
Copy link
Member

The fact that the underlying type was a HashTable was an implementation detail and users should not have relied on it. They should have coded against IDictionary instead.
It has been changed in #1767 and #305 (#755) for allowing supporting generic dictionaries (IDictionary<string, object>). Fix your code by querying for IDictionary or IDictionary<string, object>. Do not query against the current underlying concrete type.

@futurify-ydang
Copy link
Author

Thanks @bahusoid and @fredericDelaporte

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

No branches or pull requests

3 participants