-
Notifications
You must be signed in to change notification settings - Fork 302
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
Left joined nullable fields causing conversion issue #17
Comments
Hey Chris, Thanks for the bug report. Cheers, |
After bit more research, it appears to affect only members with Nullable type. I'm using MySQL as the database and columns causing this issue are defined in the database as INT(10) UNSIGNED NOT NULL. Types interpreted as DECIMAL, FLOAT, DOUBLE, INT and STRING do not seem to cause a problem. When such a field is used on the left side of a left join it could null so Entity Framework will set up this field as Nullable rather than just long. Because the property is defined as nullable, when dstType is passed to Convert.ChangeType it is reading Nullable rather than the underlying data type and any non-null value causes a problem. My SafeConvert method gets the underlying data type and uses that if the value is not null or returns null if the value is null. I set up a simple test like this (obviously an ID column would not usually be null - in this case remember it was defined like this because it was on the left side of the join). I have included decimal and int types to show these do not cause the problem: POCO:
Request:
If you change public Nullable ItemID { get; set; } to public long ItemID { get; set; } you won't get the problem. Please let me know if you need more info. Thanks Chris |
Hi Chris, I have managed to reproduce this and fix it with your suggestions. Cheers, |
I just downloaded the latest branch and so far so good. Thanks for the speedy fix. Chris |
I use Entity Framework mappings with NPoco and I have a view using a left join. The numeric fields on the joined table are represented as nullable which causes a problem in NPoco when converting the data.
A typical error looks like this:
My solution is a SafeConvert method which gets the underlying type and uses that to convert the data instead.
On line 448 of PocoData.cs I changed:
to:
and the method looks like this:
I haven't tested this to destruction yet but I'll let you know if I run into any problems while developing the rest of my application.
If this fix could be added to the next build that would be appreciated.
Thanks
Chris
The text was updated successfully, but these errors were encountered: