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
Generate "IS NULL" for nullable types with value of null #62
Comments
Hi John,
where there's a hard-coded "=" equal sign. |
Hi, Thanks for the help. I modified the method and it seems to work for my test case. I pass in the whereConditions, do a simple check to see if the parameter is null then use 'is null' or '=' accordingly. Any comments or advice welcomed. Cheers!
|
Good suggestion. I will get this added soon |
I looked at this a little closer and really don't like the idea of implementing something that has to be in a try/catch to work. Could you use the manual where method for this case? var user = connection.GetList("where age = 10 or Name like '%Smith%'"); or in your case: var user = connection.GetList("where ParentId is null AND CompanyId = 1"); You could easily generate a different where clause depending on if the ParentId is null. |
Hi there, I included the try/catch as I'd tested it for my use case but not a lot of others. I figured if it failed at least it would default back to the standard functionality. If tested for more scenarios the try/catch could probably be removed? I guess the reason I was hoping for this feature (and #63) is that I'm dropping SimpleCRUD in as a default generic Repository for my projects. It's really handy to use before creating a more specific data layer with custom SQL etc. It means that I can use the same Repository for all my POCO's and it really speeds that initial development phase up for me. I'm using this feature (and #63) in my current project and it's saved lots of time. It just feels like it follows the 'simple' ethos of SimpleCRUD. Anyway, that' just my 2 cents :). It's a great utility and I really appreciate your time on it and respect your decision going forward.
|
Hi Eric, I would like to ask (if not too bold) to discuss this one a little further? I think the auto-generation of the 'IS NULL' operator is essential for the library to maintain it's 'simple' ethos. If you are really against it, I wonder if there's a compromise to be made with a configuration flag option? The main reason I'd like it included as well is so I don't have to maintain a custom modified version of SimpleCRUD on my side. For example today when you updated #63 I would have to reapply my custom changes etc. Not trying to be a pain. Really love the library and would love to be able to use it this way out of the box. Many thanks, John |
Hi John, I'm having a look over the weekend to see if I can't come up with something that doesn't require a try-catch. To be able to pass "null" values as part of a where-condition seems logical and I for one would be grateful if I don't have to fall back on raw-sql to get this to work. Cheers, |
Couldn't resist :) Based on John' proposal, but without the need to do a try-catch
Essentially, the functions that use 'object whereContions', should pass this object along to the BuildWhere function in order to allow inspection of the property values. I created the following test method, which successfully passes:
@ericdc1, I think, but am not sure, you want to exit the for-loop after the property is found on sourceEntity. I've added this in, but it's commented out as I'm not sure if my interpretation is accurate. Cheers, |
This will be in the next release. Thanks for the code above. My main resistance is the slippery slope where people then will want greater than, less than, not equal, between, etc which is why there is a where clause option. I can see the use case for this without breaking existing functionality. |
Hi,
First of all thanks for creating such a handy utility, I really appreciate your efforts!
Not sure if I can put this question here or not, apologies if it's the wrong place. I asked the full question here: http://stackoverflow.com/questions/33862504/dapper-simplecrud-isnull
Basically wondering if SimpleCRUD can auto-detect that a nullable integer is null and generate an "IS NULL" where clause if it is? Not sure if the functionality exists or not, apologies if I've missed it.
Thanks again,
John
The text was updated successfully, but these errors were encountered: