我有一个存储过程与3输入参数.
... PROCEDURE [dbo].[gama_SearchLibraryDocuments]
@Keyword nvarchar(160),
@CategoryIds [dbo].[IntList] READONLY,
@MarketIds [dbo].[IntList] READONLY ...
Run Code Online (Sandbox Code Playgroud)
其中IntList是用户定义的表类型.
CREATE TYPE [dbo].[IntList]
AS TABLE ([Item] int NULL);
Run Code Online (Sandbox Code Playgroud)
我的目标是用dapper调用这个存储过程.
我找到了一些关于使用dapper传递用户定义类型的示例.其中之一是在Dapper.Microsoft.Sql nuget包中实现的TableValuedParameter类.
var list = conn.Query<int>("someSP", new
{
Keyword = (string)null,
CategoryIds = new TableValuedParameter<int>("@CategoryIds", "IntList", new List<int> { }),
MarketIds = new TableValuedParameter<int>("@MarketIds", "IntList", new List<int> { 541 })
}, commandType: CommandType.StoredProcedure).ToList();
Run Code Online (Sandbox Code Playgroud)
上面写的代码抛出
An exception of type 'System.NotSupportedException' occurred in Dapper.dll but was not handled in user code
Additional information: The member CategoryIds of type Dapper.Microsoft.Sql.TableValuedParameter`1[System.Int32] …Run Code Online (Sandbox Code Playgroud) 例如,我们有一个多维的双维数组
double[,] d = new double[1,2];
d.GetType() 回报 {Name = "Double[,]" FullName = "System.Double[,]"}
d[0,0]被编译为call instance float64 float64[0..., 0...]::Get(int32, int32)IL
如何System.Double[,]生成类型的源代码?它是在CLR中烘焙还是Roslyn负责它的产生?
我正在使用Dapper来处理sql数据库.我的网站项目中有一些搜索逻辑.
我的搜索获取字符串参数列表.
//filter is list of strings
var sql = new StringBuilder();
sql.Append("SELECT LibraryDocumentId FROM LibraryDocumentKeywords WHERE ");
sql.Append(string.Join("OR ", filter.Select(f => string.Format("LOWER(Keyword) LIKE '%{0}%'", f)).ToList()));
var isList = conn.Query<int>(sql.ToString()).ToList();
Run Code Online (Sandbox Code Playgroud)
实际上我不想使用这种生成动态SQL查询的方法,因为Dapper会缓存每一个查询.我宁愿通过参数传递过滤器.有人可以帮助我吗?任何的想法 ?