Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Parameterized DAX Queries with ADOMD.NET

Open goluhaque opened this issue 9 years ago • 1 comments

connection.Query(query, DynamicParameters) gives a System.NotSupportedException when using DAX with ADOMD.NET. I am on Dapper version 1.50.2. The query when not used with parameters runs fine. The code is:-

IList<dynamic> values = new List<dynamic>() { "true" }; var p = new DynamicParameters(); for (int index = 0; index < values.Count; index++) p.Add("P" + index, values.ElementAt(index)); dynamic results = connection.Query(query, p);

The query itself:- "DEFINE VAR __DS0FilterTable1 = FILTER(KEEPFILTERS(VALUES('Calendar'[Last 12 Months Indicator])), ('Calendar'[Last 12 Months Indicator] = @P0)) EVALUATE SUMMARIZECOLUMNS('Calendar'[CalendarMonthNumber], 'Calendar'[Calendar Month], __DS0FilterTable1)";

The exact exception:-

"Message": "An error has occurred.", "ExceptionMessage": "Specified method is not supported.", "ExceptionType": "System.NotSupportedException", "StackTrace": " at Microsoft.AnalysisServices.AdomdClient.AdomdParameter.get_DbType()\r\n at Dapper.DynamicParameters.AddParameters(IDbCommand command, Identity identity)\r\n at Dapper.DynamicParameters.Dapper.SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, Identity identity)\r\n at Dapper.SqlMapper.<>c__DisplayClass151_0.b__0(IDbCommand cmd, Object obj)\r\n at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action2 paramReader)\r\n at Dapper.SqlMapper.<QueryImpl>d__1251.MoveNext()\r\n at System.Collections.Generic.List1..ctor(IEnumerable1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)\r\n at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable1 commandType)\r\n at Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable`1 commandType)\r\n at OEMService.BusinessAccess.Services.DataService.d__10.MoveNext()

goluhaque avatar Oct 09 '17 07:10 goluhaque

This would be a bug to file against the provider - accessing .DbType on a parameter is part of the base ADO.NET interface, and it seems they don't support that here. If they fix it on the provider side, Dapper will start working correctly :)

NickCraver avatar May 10 '21 01:05 NickCraver