-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
STIsValid returning incorrect result for parameterized query #85
Comments
If you send in the text as a parameter (instead of as geography type) and convert to geography server-side do you get the same result? |
That's what the second parameter in the sample is doing -- passing in the text and creating the geography server-side. It returns the correct result for STIsValid, unlike passing in the geography, which returns an incorrect result. I assume there's a performance hit to convert the geography to text client-side and back to geography server-side. |
Some more information: It look like SQL Server's call to STIsValid returns whatever the geography object's internal _isValid is set to. If you create the geography in the sample client-side, the internal _isValid value is true. When you send the object up as a parameter and call STIsValid(), it returns true. But if you use reflection to set _isValid to false before sending the parameter, SQL returns false. SQL isn't recalculating isValid, but essentially trusting that the client set it correctly. |
MakeValid has a similar problem--SQL doesn't modifiy the geometry to make it valid if the internal _isValid is already true. |
Whaaaaat? That’s just ridiculous 🤦♂️🤦♂️🤦♂️ |
Here's a way to pass the geometry as a parameter and force the server to reevaluate isValid:
Similarly, if you want MakeValid to work, it's
Yuck, but it appears to work. |
I'm trying to work around the lack of a STIsValid() method on SqlGeometry by handing the geometry to SQL to evaluate. But for an invalid self-intersecting polygon, the result comes back as valid if I try to pass the geometry in as a parameter. In the following, isValid1 and isValid2 should match, but they don't. Am I missing something? The SQL connection string can point to any SQL Server instance you want. Using the 1.5.0 version for System.Data.SqlClient compatibility.
The text was updated successfully, but these errors were encountered: