• EntityFramework 两个参数连续(中间有空格)问题


    昨天在项目中,用到 EntityFramework 通过SQL语句查询。

    具体的SQL语句如下:

    SELECT
        t.*
    FROM
        (
            SELECT
                c.id AS CommunityId,
                c.`name` AS CommunityName,
                ASTEXT(c.spatial_data) AS CommunitySpatialData,
                s.id AS StreetId,
                s.`name` AS StreetName,
                ASTEXT(s.spatial_data) AS StreetSpatialData,
                MBRContains (s.spatial_data ,ST_GeometryFromText('Point(@Longitude @Latitude)')) AS streetIn,
                MBRContains (c.spatial_data ,ST_GeometryFromText('Point(@Longitude @Latitude)')) AS communityIn
            FROM
                community c
            LEFT JOIN street s ON c.street_id = s.id
        ) AS t
    WHERE
        t.streetIn = 1
    AND t.communityIn = 1;

    应该说这样没有问题的,但是查询一直报错:“Invalid GIS data provided to function st_geometryfromtext.”

    换了多种传参方式,但是都还有问题。

    经过各种调试、修改参数,大致可以确定是:两个参数是连续的,中间有空格,但是在参数替换后空格替换没了,导致数据格式出错。

    再次调整下传的参数就可以,修改后SQL语句:

    SELECT
        t.*
    FROM
        (
            SELECT
                c.id AS CommunityId,
                c.`name` AS CommunityName,
                ASTEXT(c.spatial_data) AS CommunitySpatialData,
                s.id AS StreetId,
                s.`name` AS StreetName,
                ASTEXT(s.spatial_data) AS StreetSpatialData,
                MBRContains (s.spatial_data ,ST_GeometryFromText(@point)) AS streetIn,
                MBRContains (c.spatial_data ,ST_GeometryFromText(@point)) AS communityIn
            FROM
                community c
            LEFT JOIN street s ON c.street_id = s.id
        ) AS t
    WHERE
        t.streetIn = 1
    AND t.communityIn = 1;

    对应的 point 是:

    string point = "Point(" + Longitude + " " + Latitude + ")";

    虽然知道了问题,也解决了,但是没有彻底解决这个问题。

    有知道的可以告知下。

    注意:

    1、对于面数据:最后一个点应该是第一个点,这样在入库的时候才正确,否则报错“Invalid GIS data provided to function st_geometryfromtext.”

  • 相关阅读:
    实时黄金价格[自动刷新]
    ping不通动态域名,解决方法
    清除新版阿里旺旺2008自动添加的右键菜单
    MPLS 原理详解
    windows远程桌面缺陷单用户和多用户
    Flash player ActiveX 9错误的解决办法
    关于DHCP原理的讲解
    找回丢失的IE、网上邻居等桌面图标
    xp安装了SP3以后无法更新的解决办法(XP自动更新下载后安装失败)
    ADSL 定时断线重连bat文件 [转载]
  • 原文地址:https://www.cnblogs.com/zhurong/p/9476077.html
Copyright © 2020-2023  润新知