Created
January 10, 2012 16:07
-
-
Save marek-stoj/1589779 to your computer and use it in GitHub Desktop.
Problem with dynamic parameters in Dapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When running this code, I get SqlException with this message: "Incorrect syntax near '@MaxCount'.". Why isn't the @MaxCount parameter replaced with the given value? | |
public IEnumerable<ArticleInfo> GetPopularArticles(Date fromDate, Date toDate, int maxCount) | |
{ | |
var popularArticles = new List<ArticleInfo>(); | |
IEnumerable<dynamic> rawArticles; | |
using (var connection = CreateOpenedConnection()) | |
{ | |
string queryText = | |
" select top @MaxCount" + | |
" au.Url," + | |
" am.Title," + | |
" av.[Count] as ViewsCount" + | |
" av.[Date]" + | |
" from ArticleViews av" + | |
" left join ArticleUrls au on av.ArticleId = au.Id" + | |
" left join ArticleMetadata am on am.ArticleId = au.Id" + | |
" order by av.[Count] desc, av.[Date] desc, am.Title, au.Id"; | |
rawArticles = | |
connection.Query( | |
queryText, | |
new { MaxCount = maxCount }); | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment