我使用的SP在SQL Management Studio中应该正常工作,但这是唯一一个在我的项目中得到错误结果的查询。
SP查询是:
SELECT DISTINCT Vehicle_Model_Range.ModelRange_ID, Users.MapLat,
Users.MapLong, Users.User_ID, Users.Status_ID, Vehicle_Details.Approved,
Vehicle_Details.Vehicle_Type
FROM
Users INNER JOIN
Vehicle_Details ON Users.User_ID =
Vehicle_Details.User_ID INNER JOIN
Vehicle_Make ON Vehicle_Details.Make_ID =
Vehicle_Make.Make_ID INNER JOIN
Vehicle_Model ON Vehicle_Details.Model_ID =
Vehicle_Model.Model_ID INNER JOIN
Vehicle_Model_Range ON Vehicle_Model.ModelRange_Id =
Vehicle_Model_Range.ModelRange_ID
WHERE
(Vehicle_Details.Approved = 1)
AND (Users.Status_ID = 1)
AND (Vehicle_Details.Vehicle_Type = 'V')
AND (Users.MapLat IS NOT NULL)
AND (Users.MapLong IS NOT NULL)
AND (Vehicle_Model_Range.ModelRange_ID IS NOT NULL)
这是VS中使用它的代码:
public ActionResult Search(string Location)
{
GoogleMapEntities GE = new GoogleMapEntities();
var GetVeh = db.GetMapSearch().Where(x =>
(x.ModelRange_ID.ToString().StartsWith(Location)) && (x.Vehicle_Type
== "V") && (x.Status_ID == 1) && (x.Approved == true)).ToList();
return Json(GetVeh, JsonRequestBehavior.AllowGet);
}
基本上,会发生的是它将所有点绘制到地图上并且不遵循where语句,该语句表示它应该仅针对以下条件进行绘制:
WHERE
(Vehicle_Details.Approved = 1)
AND (Users.Status_ID = 1)
AND (Vehicle_Details.Vehicle_Type = 'V')
AND (Users.MapLat IS NOT NULL)
AND (Users.MapLong IS NOT NULL)
AND (Vehicle_Model_Range.ModelRange_ID IS NOT NULL)
我已经更新了模型几次,SP无效。
编辑:
我刚刚在linq查询中添加了那些条件,但仍然不起作用。有什么想法吗?
编辑:完整存储过程
USE [X_DB]
GO
/****** Object: StoredProcedure [dbo].[sp_App_MapSearch] Script Date:
2017/06/26 9:16:10 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[sp_App_MapSearch]
AS
BEGIN
SELECT DISTINCT Vehicle_Model_Range.ModelRange_ID, Users.MapLat,
Users.MapLong, Users.User_ID, Users.Status_ID, Vehicle_Details.Approved,
Vehicle_Details.Vehicle_Type
FROM Users INNER JOIN
Vehicle_Details ON Users.User_ID =
Vehicle_Details.User_ID INNER JOIN
Vehicle_Make ON Vehicle_Details.Make_ID =
Vehicle_Make.Make_ID INNER JOIN
Vehicle_Model ON Vehicle_Details.Model_ID =
Vehicle_Model.Model_ID INNER JOIN
Vehicle_Model_Range ON Vehicle_Model.ModelRange_Id =
Vehicle_Model_Range.ModelRange_ID
WHERE
(Vehicle_Details.Approved = 1)
AND (Users.Status_ID = 1)
AND (Vehicle_Details.Vehicle_Type = 'V')
AND (Users.MapLat IS NOT NULL)
AND (Users.MapLong IS NOT NULL)
AND (Vehicle_Model_Range.ModelRange_ID IS NOT NULL)
END