-
Notifications
You must be signed in to change notification settings - Fork 936
NH-2401 - Method for specifying IType of LINQ parameter #346
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
Conversation
Construct several test cases with basically the same query, but using different "mapped as", in such a way that the outcome of the different queries are different. For instance, if a datetime is treated as a date the time of day will be lost, which could perhaps give different results with a comparison operator. Or a string property with different length. |
Thanks, will try. BTW, these errors don't occur on my machine...:-/ |
I have added some unit tests and support for type conversions, as currently supported (ToString(), Convert.ToInt32(), Convert.ToDecimal() and Convert.ToDouble()). from Orders o where Convert.ToInt32(o.OrderDate.MappedAs(NHibernateUtil.Int32)) ... as well as the previous kind: |
Any feedback on this? Can this make it to 4.1? |
Set to 4.1.0, but I don't like the implementation. Will look closer at the weekends. |
Why don't you like it? |
@@ -10,6 +10,12 @@ namespace NHibernate.Linq | |||
{ | |||
public static class LinqExtensionMethods | |||
{ | |||
public static T MappedAs<T>(this T parameter, NHibernate.Type.IType type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This random thought: can we have different MappedAs
for all IType
which can make sense, instead of generic one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this:
public static decimal MappedAs(this decimal parameter, NHibernate.Type.IType type)
?
Sure... it may make sense... want me to update the pull request?
BTW, not related, but why don't we also support, at least, Convert.ToDateTime() in a LINQ query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooray, you've learnt how to use line comments... sorry, just trying to joke.
Like this:
public static decimal MappedAs(this decimal parameter, NHibernate.Type.IType type)
Probably
public static decimal MappedAs(this decimal parameter, NHibernate.Type.DecimalType type)
But I see now, that this is a bad idea.
but why don't we also support, at least, Convert.ToDateTime() in a LINQ query?
Just because (c) my 4yo. Just because we forgot to support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a specific type, we need to allow passing arbitrary types! BTW, why is that a bad idea?
I dont know why I did not like it when I'd written, it was just my feeling. |
|
The generic version will show up in intellisense everywhere. The impact will be mitigated if you gather nhibernate linq queries in e.g. repository or query classes so you don't include the namespace everywhere. But I guess there's not many alternatives. |
@rjperes but why in your version .MappedAs applied to a property of a mapped class instead of an parameter? |
Hmm, now that you mention it... Not sure! Will check it out. |
@rjperes any updates? |
Nopes, maybe in the weekend. |
Updated pull request to make it clear that the MappedAs extension can be applied to the parameter or the property. |
…vert.ToDouble(), Convert.ToDecimal()) and added unit tests
@rjperes I'm going to remove See here: master...hazzik:NH-2401 |
It seems that |
Implementation and simple unit test
https://nhibernate.jira.com/browse/NH-2401
@oskarb @hazzik: Debugging the code, it is clear that the parameter type is being correctly set, but I'm not sure how to do it in a unit test, have you got any suggestions?