我具有用於從LINQ從多個表中搜索作爲執行查詢模式錯誤的同時從LINQ retriving數據到SQL
`ALTER PROCEDURE [dbo].[rdsp_Srchfld]
(
@strFldlst as nvarchar(max),
@strTblnm as nvarchar(max),
@intSrchStyle as int,
@strcond1 as nvarchar(250),
@strCond2 as nvarchar(250)=null,
@strCond3 as nvarchar(300)
)
AS
BEGIN
declare @strSql as varchar(7000)
--Process
set @strSql = 'select Distinct ' + @strFldlst + ' from ' + @strTblnm
IF @intSrchStyle = 0
BEGIN
SET @strSql = @strSql + ' where ' + @strcond1 + ' = ' + '''' + @strCond2 + '''' + ' order by ' + '' + @strcond3 + ''
END
ELSE IF @intSrchStyle = 1
BEGIN
SET @strSql = @strSql + ' where ' + @strcond1 + ' like ' + '''' + @strCond2 + '%' + '''' + ' order by ' + '' + @strcond3 + ''
END
ELSE IF @intSrchStyle = 2
BEGIN
SET @strSql = @strSql + ' where ' + @strcond1 + ' like ' + '''' + '%' + @strCond2 + '%' + '''' + ' order by ' + '' + @strcond3 + ''
END
EXEC (@strSql)
END`
和傳遞參數到SQL作爲
var rslt = from srch in custDC.rdsp_Srchfld(fldName, tblName, srchType, cond1, cond2, cond3) select srch;
存儲過程現在我試圖建立我的程序,我得到的錯誤爲
Error 1 Could not find an implementation of the query pattern for source type 'int'. 'Select' not found.
爲什麼我得到錯誤a我該如何執行它。
當您使用Linq-To-Sql時,爲什麼要在SP中使用動態SQL?這種方法結合了SP的所有危險和不靈活性,同時避免了任何好處。如果使用得當,出於正確的原因,他們可以快速而安全。 – Jodrell
可以爲此SP編譯什麼查詢計劃? – Jodrell
@Jodrell:通過傳遞表名和字段名作爲參數從多個表中檢索數據。 –