Unfortunately that throws an exception:
System.ArgumentException : 24144: This operation cannot be completed because the instance is not valid. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a geometry instance to shift slightly.
at Microsoft.SqlServer.Types.SqlGeography.ThrowIfInvalid()
at Microsoft.SqlServer.Types.SqlGeography.STDistance(SqlGeography other)
The SQL being generated for the original query (where ordering isn't working) looks like:
declare @p4 sys.geography
set @p4=convert(sys.geography,0xE6100000010401020000BB551070F21B42C0B9F540A67CF165408AE4A752F51A42C045BF2FA52CF16540E935D461FB1942C0C2B967B4DBF065405F4DFBA6041942C0A45E05D789F06540DB9C632B111842C03B5C2D1037F0654020B233F8201742C059770C63E3EF654080E57116341642C0E06CD7D28EEF6540B609048F4A1542C00CD3CA6239EF65400A1DAF6A641442C0A4FA2A16E3EE654097FB16B2811342C0F3CF43F08BEE6540E012BE6DA21242C098BB68F433EE65408B1605A6C61142C03883F425DBED654071B62A63EE1042C0F229498881ED6540D0554BAD191042C0C6D0CF1E27ED6540D6C3608C480F42C0BF96F8ECCBEC654063F541087B0E42C0FF783AF66FEC65400BC0A228B10D42C0B032133E13EC65405F9613F5EA0C42C0BF1C07C8B5EB654085450175280C42C07F0DA19757EB65400AB4B4AF690B42C02E3872B0F8EA654006A252ACAE0A42C0490C121699EA6540856ADB71F70942C0D3141ECC38EA654042C62A07440942C069D739D6D7E96540A88FF772940842C049B30E3876E965402388D3BBE80742C02CC04BF513E96540C81E2BE8400742C010ADA511B1E86540433845FE9C0642C0D69ED6904DE8654019F84204FD0542C0DC0E9E76E9E76540488B1F00610542C05CA9C0C684E765402CF4AFF7C80442C0D52B08851FE76540BDD7A2F0340442C0394343B5B9E665402D4C80F0A40342C01F6A455B53E66540D7A8A9FC180342C0C7C6E67AECE565407957591A910242C01909041885E56540E5A6A24E0D0242C07E487E361DE56540E99E719E8D0142C0B2E13ADAB4E46540B4D58A0E120142C0765423074CE4654079468BA39A0042C0362125C1E2E365408629E861270042C095A6310C79E36540A8CDEE4DB8FF41C0EDFE3DEC0EE36540F572C46B4DFF41C0B8DD4265A4E26540F72666BFE6FE41C0EE6C3C7B39E2654032A2A84C84FE41C0472A2A32CEE165400527381726FE41C07EC40E8E62E1654001629822CCFD41C076F8EF92F6E06540894B247276FD41C05A6ED6448AE06540DD0A0E0925FD41C0A796CDA71DE0654090DA5EEAD7FC41C03787E3BFB0DF65405AEEF6188FFC41C02ED8289143DF65404C5A8D974AFC41C0E880B01FD6DE65406DFBAF680AFC41C0DAB48F6F68DE6540B661C38ECEFB41C061C0DD84FADD65407FBB020C97FB41C097E5B3638CDD654044C27FE263FB41C00A392D101EDD6540D7A8221435FB41C07D7E668EAFDC6540F30AAAA20AFB41C098057EE240DC654047DEAA8FE4FA41C097869310D2DB6540CB6490DCC2FA41C0E5FEC71C63DB654093209C8AA5FA41C0C78D3D0BF4DA654004C9E59A8CFA41C0ED5017E084DA654071415B0E78FA41C00B41799F15DA65401491C0E567FA41C0680E884DA6D9654083DCAF215CFA41C06FFD68EE36D96540836099C254FA41C03AC34186C7D865403A6EC3C851FA41C01862381958D86540DC684A3453FA41C01A0673ABE8D76540B5C4200559FA41C097E1174179D765409A070F3B63FA41C0B5094DDE09D76540CBCAB3D571FA41C0EE5238879AD6654030BE83D484FA41C09E2DFF3F2BD6654011ADC9369CFA41C08882C60CBCD565402584A6FBB7FA41C0678FB2F14CD565400D591122D8FA41C07EC3E6F2DDD465404273D7A8FCFA41C0289C85146FD465405A569C8E25FB41C07681B05A00D46540BFCDD9D152FB41C0C6A287C991D36540D3F9DF7084FB41C06AD3296523D36540645ED569BAFB41C04F67B431B5D26540A2F2B6BAF4FB41C0AC0F433347D265406F32586133FC41C0B9B7EF6DD9D165400B31635B76FC41C07361D2E56BD165403CAD58A6BDFC41C05B02019FFED06540CC26903F09FD41C050608F9D91D065406BF5372459FD41C066EE8EE524D0654001615551ADFD41C0CDA90E7BB8CF654057BBC4C305FE41C0C2F61A624CCF6540337B397862FE41C08F7DBD9EE0CE6540C2583E6BC3FE41C09407FD3475CE6540776B359928FF41C05B5CDD280ACE6540434958FE91FF41C0C71E5F7E9FCD65403627B896FFFF41C040AA7F3935CD65406EFB3D5E710042C0FBEF385ECBCC654086A0AA50E70042C04D5481F061CC65403AFA9669610142C0118C4BF4F8CB6540981B74A4DF0142C01E7A866D90CB6540636E8BFC610242C0D00C1D6028CB6540F6DBFE6CE80242C0A51BF6CFC0CA65406AF7C8F0720342C0E944F4C059CA65402F29BD82010442C07DCBF536F3C96540DCDB871D940442C0AF74D4358DC9654088AAAEBB2A0542C02B6665C127C9654052909057C50542C0FE0379DDC2C86540551966EB630642C0B0CEDA8D5EC86540EA944171060742C0824151D6FAC765404F490FE3AC0742C0B3B09DBA97C765408DA8953A570842C0EC277C3E35C76540BE867571050942C0C248A365D3C66540A6512A81B70942C05329C43372C6654093490A636D0A42C0FC328AAC11C66540A1BB4610270B42C038019BD3B1C56540343DEC81E40B42C08C4096AC52C56540CAE8E2B0A50C42C0988D153BF4C46540259CEE956A0D42C05454AC8296C46540AE37AF29330E42C055AFE78639C4654026DFA064FF0E42C049474E4BDDC36540A83B1C3FCF0F42C0863260D381C36540EABE56B1A21042C0C9D4962227C36540C0E762B3791142C008BF643CCDC26540EA87303D541242C0778F352474C26540220B8D46321342C0B0D16DDD1BC265406ABF23C7131442C0F7DE6A6BC4C16540971E7EB6F81442C0B4BE82D16DC165401E19040CE11542C00A07041318C165401862FCBECC1642C099BD3533C3C0654082BC8CC6BB1742C0733857356FC06540B949BA19AE1842C02DFF9F1C1CC0654023D969AFA31942C02BAC3FECC9BF65401A39607E9C1A42C00CCE5DA778BF6540F888427D981B42C04BC9195128BF6540698C96A2971C42C013BA8AECD8BE6540DBFFC2E4991D42C03456BF7C8ABE654028EE0F3A9F1E42C05CCFBD043DBE65405607A798A71F42C071B58387F0BD6540A0F893F6B22042C029D90508A5BD654089C5C449C12142C0D12E30895ABD654026220A88D22242C04CB1E50D11BD654078CE17A7E62342C042450099C8BC654001F3849CFD2442C0929C502D81BC6540627ECC5D172642C0EE199ECD3ABC654013844DE0332742C0B8B4A67CF5BB65404C9C4B19532842C020DD1E3DB1BB6540E944EFFD742942C06B60B1116EBB654076434683992A42C08A4DFFFC2BBB65404508449EC02B42C0E5D99F01EBBA65409612C243EA2C42C066462022ABBA6540CA558068162E42C0C5C403616CBA6540A89F2501452F42C0135DC3C02EBA65409AFF3F02763042C092D3CD43F2B96540082F4560A93142C0BA8E87ECB6B965409BFA920FDF3242C0A07D4ABD7CB9654093AC6F04173442C08AFE65B843B9654014780A33513542C0D7C51EE00BB9654067E57B8F8D3642C030C5AE36D5B86540413FC60DCC3742C0F81245BE9FB86540E900D6A10C3942C017D205796BB865406B45823F4F3A42C0011A0A6938B865409B378DDA933B42C016DF5F9006B865401C83A466DA3C42C04CDB09F1D5B7654045C661D7223E42C02577FF8CA6B76540E6044B206D3F42C0FFB22C6678B76540F71BD334B94042C0B010727E4BB7654023365A08074242C0787DA4D71FB765402E412E8E564342C0463C8D73F5B6654032648BB9A74442C054D0E953CCB66540AD769C7DFA4542C01EE86B7AA4B6654069787BCD4E4742C0AC48B9E87DB66540250A329CA44842C03CB96BA058B665401CE7B9DCFB4942C042EF10A334B665402F5FFD81544B42C0C97A2AF211B66540FBD1D77EAE4C42C02EB32D8FF0B565408E2A16C6094E42C041A4837BD0B56540E95B774A664F42C0C1FB88B8B1B565402FDEACFEC35042C037F78D4794B565408E2C5BD5225242C04152D62978B56540D0431AC1825342C0363599605DB56540A02176B4E35442C0332401ED43B565407344EFA1455642C08FEE2BD02BB565400F2CFB7BA85742C0BE9E2A0B15B56540B8DA04350C5942C0966A019FFFB46540F6566DBF705A42C001A4A78CEBB46540F32D8C0DD65B42C01FAA07D5D8B4654066F6AF113C5D42C0D3DAFE78C7B4654011D41EBEA25E42C0C4845D79B7B46540CCFB16050A6042C0C5D9E6D6A8B465400B38CFD8716142C0B8E150929BB46540F16D772BDA6242C0E56D44AC8FB46540D62239EF426442C0BB0C5D2585B4654049023816AC6542C016FE28FE7BB4654084649292156742C0EA27293774B465404FD561567F6842C07A0BD1D06DB46540509BBB53E96942C0FCBA86CB68B46540B53FB17C536B42C0B7CFA22765B46540541651C3BD6C42C0AA6070E562B4654005C6A619286E42C0A3F92C0562B4654075D1BB71926F42C0D892088762B46540352098BDFC7042C00989256B64B465401C8842EF667242C0179698B167B46540F156C1F8D07342C023CA685A6CB4654052DC1ACC3A7542C033858F6572B46540DEF3555BA47642C05871F8D279B465409A8F7A980D7842C05D7D81A282B465407F429275767942C0F8D7FAD38CB4654033CBA8E4DE7A42C08AEB266798B46540009FCCD7467C42C0665ABA5BA5B46540CD740F41AE7D42C09FFB5BB1B3B4654058D08612157F42C065D8A467C3B46540648D4C3E7B8042C0F329207ED4B46540186B7FB6E08142C0FE574BF4E6B465405097436D458342C0C3F795C9FAB46540103AC354A98442C098CB61FD0FB56540E1002F5F0C8642C011C3028F26B5654035AABE7E6E8742C0BFFBBE7D3EB56540C090B1A5CF8842C072C2CEC857B56540C5364FC62F8A42C01F955C6F72B5654041D1E7D28E8B42C04F2585708EB5654007D3D4BDEC8C42C02A5B57CBABB56540B8777979498E42C01059D47ECAB56540914E43F8A48F42C0D67FEF89EAB565400AC5AA2CFF9042C091738EEB0BB665404FB13309589242C0F82089A22EB665406EDC6D80AF9342C067C3A9AD52B66540518CF584059542C079EBAC0B78B66540740D74095A9642C0388641BB9EB665404B3CA000AD9742C0EEE408BBC6B66540570E3F5DFE9842C096C59609F0B66540E81A24124E9A42C0D85B71A51AB76540812332129C9B42C0B45A118D46B76540D29B5B50E89C42C0C5FEE1BE73B765405131A3BF329E42C01E194139A2B765405E521C537B9F42C0CA1A7FFAD1B76540EFB4EBFDC1A042C0E420DF0003B86540CADC47B306A242C05B01974A35B865402FA1796649A342C04758CFD568B8654000B2DC0A8AA442C0E795A3A09DB865405F1CE093C8A542C0380D22A9D3B86540A6CE06F504A742C035034CED0AB96540DB1BE8213FA842C0AEBE156B43B965406A3E300E77A942C0C89866207DB9654048DAA0ADACAA42C0120E190BB8B96540607E11F4DFAB42C045D0FA28F4B965404F2570D510AD42C0A5D8CC7731BA654057B5C1453FAE42C0F47A43F56FBA6540AC7F22396BAF42C01879069FAFBA6540E0BEC6A394B042C05217B172F0BA65408514FB79BBB142C01E31D26D32BB6540080625B0DFB242C0B14EEC8D75BB6540A478C33A01B442C010BB75D0B9BB65407C2C6F0E20B542C0CF9AD832FFBB6540C036DB1F3CB642C0660373B245BC6540027BD56355B742C02E13974C8DBC65406E2347CF6BB842C0F1098BFED5BC65402C1835577FB942C01C6289C51FBD6540B275C0F08FBA42C093EAC09E6ABD65400E0227919DBB42C014E15487B6BD65402BA1C32DA8BC42C0410D5D7C03BE6540FCC70EBCAFBD42C040DCE57A51BE654095EE9E31B4BE42C0EF7CF07FA0BE65404326AD7FB5BF42C071830987F0BE6540D6CAA5A0B3C042C001837C8E41BF65406B857C8AAEC142C05AC9299393BF6540F3BC4433A6C242C086DDE691E6BF6540590232919AC342C0099F7E873AC06540887B989A8BC442C09D65B1708FC065401F4DED4579C542C08321354AE5C06540E102C78963C642C0617CB5103CC16540D9F6DD5C4AC742C0B4FAD3C093C1654029B70CB62DC842C0D11D2857ECC16540846A508C0DC942C072863FD045C265403633C9D6E9C942C0CD179E28A0C26540F290BA8CC2CA42C0381BBE5CFBC2654001C18BA597CB42C05E64106957C36540291DC81869CC42C0E475FC49B4C365401A791FDE36CD42C0B6A6E0FB11C46540477E66ED00CE42C0B447127B70C465406906973EC7CE42C002CADDC3CFC465405674D0C989CF42C0C2E586D22FC565406B0B588748D042C057C148A390C565405D45996F03D142C026195632F2C565407626267BBAD142C0CB67D97B54C665403590B7A26DD242C0D20EF57BB7C6654067922DDF1CD342C0DC7FC32E1BC7654080BA8F29C8D342C0416657907FC7654060610D7B6FD442C025D1BB9CE4C7654073F7FDCC12D542C0F85DF44F4AC86540114FE118B2D542C06B63FDA5B0C865402BE55F584DD642C0CF1CCC9A17C965405A284B85E4D642C0DFD54E2A7FC965400EBE9D9977D742C0F3166D50E7C9654017C67B8F06D842C096D1070950CA65405B1C336191D842C0808DF94FB9CA6540D0983B0918D942C0F595162123CB6540A14D37829AD942C07E272D788DCB65407DC3F2C618DA42C0FF9D0551F8CB65402D3465D292DA42C026A362A763CC654031C3B09F08DB42C0315D0177CFCC65409DB4222A7ADB42C00A9E99BB3BCD65400EA2336DE7DB42C0B312DE70A8CD6540BAAD876450DC42C0FE727C9215CE6540A8B3EE0BB5DC42C09AB11D1C83CE6540F378645F15DD42C0572C6609F1CE654033D9105B71DD42C0CCDCF5555FCF6540E8F147FBC8DD42C0248968FDCDCF6540084C8A3C1CDE42C043F555FB3CD065408B03851B6BDE42C01714524BACD065400DED1195B5DE42C03239EDE81BD165407CB937A6FBDE42C0924AB4CF8BD16540BD172A4C3DDF42C0A8F230FBFBD165406CD449847ADF42C084D2E9666CD265408CF7244CB3DF42C03EB4620EDDD265404BE076A1E7DF42C081BD1CED4DD36540B55E288217E042C048A296FEBED365406CCB4FEC42E042C0B7D74C3E30D46540641D31DE69E042C01EC7B9A7A1D465408CFD3D568CE042C01E01563613D5654081D81553AAE042C0E07098E584D5654029EE85D3C3E042C0738FF6B0F6D56540595F89D6D8E042C03897E49368D665405B39495BE9E042C062B7D589DAD665408A7F1C61F5E042C08C473C8E4CD76540C13288E7FCE042C058FB899CBED76540DD563FEEFFE042C0121630B030D865401EF62275FEE042C06B9E9FC4A2D865409222427CF8E042C0239249D514D965405FF5D903EEE042C0C4199FDD86D96540138C550CDFE042C053BC11D9F8D96540E2034E96CBE042C0F79213C36ADA6540D5728AA2B3E042C0A57C1797DCDA6540FEDEFF3197E042C0AE5191504EDB65408E33D14576E042C05017F6EABFDB6540F3334FDF50E042C02133BC6131DC6540E66CF8FF26E042C07A9E5BB0A2DC6540712379A9F8DF42C0B5194ED213DD6540F441ABDDC5DF42C05E5F0FC384DD65401F43969E8EDF42C041571D7EF5DD6540ED1A6FEE52DF42C04C49F8FE65DE65409B1D98CF12DF42C05F102341D6DE65409DE4A044CEDE42C0E64C234046DF65409431465085DE42C0469781F7B5DF654050CF71F537DE42C028B2C96225E06540BE703A37E6DD42C08BBC8A7D94E06540018EE31890DD42C0A163574303E16540723FDD9D35DD42C07614C6AF71E16540BD16C4C9D6DC42C0632D71BEDFE165400AF660A073DC42C0372FF76A4DE265402EE5A8250CDC42C02DEEFAB0BAE26540FAE4BC5DA0DB42C09EC2238C27E3654099C0E94C30DB42C05EB91DF893E3654002DDA7F7BBDA42C0E8C399F0FFE3654088069B6243DA42C02EE84D716BE46540943C9292C6D942C02170F575D6E465406E7B878C45D942C0E51851FA40E5654031849F55C0D842C0BD4127FAAAE56540F1A229F336D842C0901A447114E66540FE729F6AA9D742C022D2795B7DE6654059A1A4C117D742C0EEC3A0B4E5E665406BAD06FE81D642C0A6A597784DE76540D4A7BC25E8D542C048B443A3B4E765409CEFE63E4AD542C0DFE090301BE865407AEDCE4FA8D442C0D6FC711C81E8654081CDE65E02D442C0E6E5E062E6E86540F236C97258D342C09BB1DEFF4AE965407B023992AAD242C06BD873EFAEE96540ACEE20C4F8D142C06260B02D12EA6540C552930F43D142C05E07ACB674EA6540E8CFC97B89D042C0D26C8686D6EA654099002510CCCF42C01D3B679937EB6540A4262CD40ACF42C063507EEB97EB654072D78CCF45CE42C0F6E60379F7EB6540BBA61A0A7DCD42C03ABD383E56EC6540B2CFCE8BB0CC42C0153D6637B4EC6540A7DCC75CE0CB42C0DDA2DE6011ED6540144D49850CCB42C0C523FDB66DED6540413ABB0D35CA42C0C8132636C9ED654055FAA9FE59C942C0150BC7DA23EE654005C2C5607BC842C0EF0A57A17DEE6540C144E23C99C742C00BA25686D6EE65408153F69BB3C642C0611050862EEF6540267A1B87CAC542C0776AD79D85EF6540809B8D07DEC442C021BC8AC9DBEF6540ED8BAA26EEC342C0AB2A120631F06540B1AAF1EDFAC242C08416205085F06540FF79036704C242C0493C71A4D8F065409E35A19B0AC142C04BD5CCFF2AF165407168AC950DC042C07EB7045F7CF16540A180265F0DBF42C0D374F5BECCF165409A6230020ABE42C0047A861C1CF26540E0FA098903BD42C0C22CAA746AF265409CCE11FEF9BB42C052095EC4B7F26540218BC46BEDBA42C091BFAA0804F365404194BCDCDDB942C0614FA43E4FF365407F91B15BCBB842C07B246A6399F365403EFA77F3B5B742C0A6312774E2F36540D8A000AF9DB642C0580B126E2AF46540B33C589982B542C0B2016D4E71F4654044F3A6BD64B442C0EC398612B7F465402AE02F2744B342C01EC7B7B7FBF46540489C50E120B242C064C2673B3FF56540F4C380F7FAB042C07662089B81F56540387C5175D2AF42C0911218D4C2F5654034F76C66A7AE42C0CA8821E402F665409AF795D679AD42C0C1DBBBC841F665406F53A7D149AC42C0AF978A7F7FF66540CF75936317AB42C0DFD23D06BCF6654010E06398E2A942C07941925AF7F6654012AA387CABA842C0BD48517A31F76540C601481B72A742C0901151636AF7654013AADD8136A642C06E9A7413A2F76540FD785ABCF8A442C0BFC8AB88D8F7654025D533D7B8A342C08779F3C00DF86540A332F3DE76A242C0779155BA41F86540468F35E032A142C05F0CE97274F865403DEEAAE7EC9F42C0FB0BD2E8A5F8654024D31502A59E42C02BE6411AD6F8654098BC4A3C5B9D42C08032770505F96540399E2FA30F9C42C02ED7BDA832F965402B5ABB43C29A42C05F156F025FF965402F3AF52A739942C0EC94F1108AF965403A68F465229842C0696FB9D2B3F96540A866DF01D09642C0A63A4846DCF965400588EB0B7C9542C084122D6A03FA65407B665C91269442C035A2043D29FA6540E85A839FCF9242C0DB2C79BD4DFA654095F3BE43779142C08B9542EA70FA6540B26A7A8B1D9042C0B96626C292FA65407C1C2D84C28E42C005D9F743B3FA654026FD593B668D42C070D9976ED2FA6540920E8FBE088C42C0F70EF540F0FA6540BBD5641BAA8A42C091DF0BBA0CFB654011D07D5F4A8942C09C74E6D827FB654095E88598E98742C0B4BE9C9C41FB6540D6EC31D4878642C0E57854045AFB6540D6013F20258542C05E2B410F71FB6540D018728AC18342C0792DA4BC86FB6540F96397205D8242C03CA7CC0B9BFB654028CB81F0F78042C0479217FCADFB654076600A08927F42C029BAEF8CBFFB6540F3D40F752B7E42C02CBCCDBDCFFB654041ED7545C47C42C08A06388EDEFB654058F624875C7B42C016D7C2FDEBFB6540413A0948F47942C05939100CF8FB6540F47412968B7842C01E04D0B802FC65405A49337F227742C074D6BF030CFC654051B66011B97542C02414ABEC13FC6540FD8B915A4F7442C0A1E16A731AFC654024E1BD68E57242C0691FE6971FFC6540D088DE497B7142C0E664115A23FC65401A88EC0B117042C0BFFAEEB925FC6540398CE0BCA66E42C0AFD48EB726FC6540CB60B26A3C6D42C0D18A0E5326FC654066665823D26B42C06352998C24FC65407809C7F4676A42C01EF6676421FC65406A39F0ECFD6842C0EFCDC0DA1CFC65402DE0C219946742C048B6F7EF16FC6540025A2A892A6642C0ED066EA40FFC6540C5ED0D49C16442C03C8992F806FC654079455067586342C0066EE1ECFCFB654053E7CEF1EF6142C0E542E481F1FB65402AAF61F6876042C01EE731B8E4FB65405548DA82205F42C005806E90D6FB654007A803A5B95D42C0F56C4B0BC7FB65401D88A16A535C42C0CC3A8729B6FB654073E26FE1ED5A42C0F196EDEBA3FB6540B86C2217895942C0ED41575390FB6540CE146419255842C09401AA607BFB6540AE7DD6F5C15642C0B492D81465FB6540EF7C11BA5F5542C0659AE2704DFB6540C898A273FE5342C0DD96D47534FB6540C4860C309E5242C0E6CFC7241AFB654006ABC6FC3E5142C0D946E27EFEFA654034983CE7E04F42C042A65685E1FA65400290CDFC834E42C00E316439C3FA65406F04CC4A284D42C05BB1569CA3FA6540AD197DDECD4B42C0DF6686AF82FA6540B72818C5744A42C0EAF4577460FA65409B42C60B1D4942C009503CEC3CFA65408FB4A1BFC64742C04BABB01818FA6540A98CB5ED714642C019653EFBF1F965406D1FFDA21E4542C0BBF37A95CAF96540188E63ECCC4342C083D107E9A1F96540AC4DC3D67C4242C08D6892F777F96540DAAEE56E2E4142C031FED3C24CF96540AE6682C1E13F42C01B9E914C20F9654009183FDB963E42C004059C96F2F8654003DEAEC84D3D42C0188BCFA2C3F865401FD75196063C42C00B0E147393F865404DB19450C13A42C0D3DA5C0962F86540E736D0037E3942C01297A8672FF8654083DC48BC3C3842C0302A0190FBF76540A34F2E86FD3642C024A67B84C6F7654069069B6DC03542C0E82F384790F765401DD0937E853442C0ADE761DA58F76540B46607C54C3342C0B3D02E4020F765404201CE4C163242C0DFB8DF7AE6F665406EE7A821E23042C00420C08CABF66540C505424FB02F42C0E71E26786FF6654030832BE1802E42C0F44D723F32F665404257DFE2532D42C0B3AB0FE5F3F56540A3E1BE5F292C42C0F782736BB4F5654068821263012B42C0C2501DD573F56540983309F8DB2942C0F4A9962432F565408423B829B92842C0A920735CEFF465405B501A03992742C06129507FABF46540B624108F7B2642C0E5FFD48F66F465403F155FD8602542C0EF8BB29020F46540553FB1E9482442C09045A384D9F36540F60895CD332342C062196B6E91F3654085C17C8E212242C07C4CD75048F36540D943BE36122142C02560BE2EFEF265405E9992D0052042C05FF5FF0AB3F26540439E1566FC1E42C026B084E866F26540E4A64501F61D42C0891A3ECA19F26540442603ACF21C42C0888726B3CBF16540BB551070F21B42C0B9F540A67CF1654001000000020000000001000000FFFFFFFF0000000003)
exec sp_executesql N'SELECT
[Party].[OrganisationName] AS [Party.OrganisationName],
[Party].[Id] AS [Party.Id],
[Party].[CardReference] AS [Party.CardReference],
[Party].[CardToken] AS [Party.CardToken],
[Party].[Country] AS [Party.Country],
[Party].[CreatedOn] AS [Party.CreatedOn],
[Party].[Currency] AS [Party.Currency],
[Party].[FirstName] AS [Party.FirstName],
[Party].[Kind] AS [Party.Kind],
[Party].[LastName] AS [Party.LastName],
[Party].[LockVersion] AS [Party.LockVersion],
[Party].[Status] AS [Party.Status],
[Party].[TimeZoneId] AS [Party.TimeZoneId],
[Party].[UpdatedOn] AS [Party.UpdatedOn],
[Party].[UserLoginId] AS [Party.UserLoginId],
[Party].[Address1] AS [Party.Address1],
[Party].[Address2] AS [Party.Address2],
[Party].[City] AS [Party.City],
[Party].[Location] AS [Party.Location],
[Party].[MerchantNumber] AS [Party.MerchantNumber],
[Party].[PaymentMax] AS [Party.PaymentMax],
[Party].[PaymentMin] AS [Party.PaymentMin],
[Party].[PaymentPlaceholder] AS [Party.PaymentPlaceholder],
[Party].[Postcode] AS [Party.Postcode],
[Party].[State] AS [Party.State]
FROM
[Party]
WHERE
(([Party].[Status] = @p0 AND [Party].[Location].STIntersects(@p1) = @p2) AND [Party].[Kind] = @p3)
ORDER BY
[Party].[Location].STDistance(@p1);',N'@p0 int,@p1 [geography],@p2 bit,@p3 int',@p0=0,@p1=@p4,@p2=1,@p3=2
If I take this and execute it manually - it still fails to change the ordering - so it appears something is failing at a SQL level somehow?
BUT, if I execute this basic piece of SQL with a few constants in it - it seems to work fine:
select * from Party where Location.STIntersects(geography::STPointFromText('POINT(174.758665 -36.856849)', 4326).STBuffer(10000000)) = 1 and Kind = 2
order by Location.STDistance(geography::STPointFromText('POINT(174.758665 -36.856849)', 4326))