Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向dapper查询动态添加参数_C#_.net_Dapper - Fatal编程技术网

C# 向dapper查询动态添加参数

C# 向dapper查询动态添加参数,c#,.net,dapper,C#,.net,Dapper,我正在尝试动态发送一个参数列表,以供查询执行。目前我有一个空间查询 SELECT top(0 + 30) ListingView.*, ROW_NUMBER() OVER (ORDER BY ListingView.BedroomsTotal ASC) AS RowNum FROM ListingView WHERE ListingView.MLSKey = 'nsmls' AND ListingView.Ficoscore = '760-850' AND ListingVie

我正在尝试动态发送一个参数列表,以供查询执行。目前我有一个空间查询

SELECT top(0 + 30) ListingView.*, ROW_NUMBER() 
OVER (ORDER BY ListingView.BedroomsTotal ASC) AS RowNum
FROM ListingView 

WHERE ListingView.MLSKey = 'nsmls' AND ListingView.Ficoscore = '760-850' AND       ListingView.LifeStyle = 'couple-no-kids' AND ListingView.LoanType = '30YrFixed'     AND ListingView.StandardStatus IN 
('active', 'pending') AND ListingView.ListPrice >1 AND     ListingView.PropertyType = 'SF' AND     (ListingView.GeoLocation.STIntersects(@GeoLocation0) = 1 OR 
ListingView.GeoLocation.STIntersects(@GeoLocation1) = 1
在此空间查询中,geolocation0和geolocation1是硬编码参数。我可能需要在查询中添加多个地理位置

我当前简洁的论点如下所示:

 var args = new
 {
 @LivingAreaMin = predicates.GetLivingAreaSqftMin(),
 @LivingAreaMax = predicates.GetLivingAreaSqftMax(),
 @GeoLocation0 = ((lstLocationPolygon != null && lstLocationPolygon.Count >   0) ? SqlGeometry.STPolyFromText(new SqlChars(new SqlString(
     string.Format("POLYGON(({0}))", lstLocationPolygon[0]))), 0) : null),

 @GeoLocation1 = ((lstLocationPolygon != null && lstLocationPolygon.Count >   1) ? SqlGeometry.STPolyFromText(new SqlChars(new SqlString(
 string.Format("POLYGON(({0}))", lstLocationPolygon[1]))), 0) : null),

 @GeoLocation2 = ((lstLocationPolygon != null && lstLocationPolygon.Count > 2) ? SqlGeometry.STPolyFromText(new SqlChars(new SqlString(
 string.Format("POLYGON(({0}))", lstLocationPolygon[2]))), 0) : null),
}       
在这种情况下,地理位置参数可能大于3或小于3,所以我需要动态添加它们。我已经使用了链接的解决方案

当我尝试使用DynamicParameters时,但给出以下错误

其他信息:必须仅为UDT参数设置UdtTypeName属性

我也尝试过IEnumerable>和Dictionary,但它给了我以下错误

必须声明标量变量@xyz,即使我正确声明了所有变量


你能给我指出正确的方向吗。

在lsLocationPolygon上迭代吗?@ThomasLindvall是的。我也有同样的问题@ThomasLindvall你能解释一下我如何通过迭代分配给args对象吗?UDT问题可以通过以下方式解决:我将所有geoLoc添加到集合对象中,并将其作为@locations添加到我的args对象中,然后将@locations添加到我的SQLquery@ThomasLindvall如何将UdtTypeName属性与dapper参数一起使用?