I am using Dapper with the SQLinq Nuget package.
Here is some sample code I am using.
Dapper with SQLinq runs the query before I run a .ToList() (for example).
I know with Dapper you can specify "buffer" to make it run deferred, but I do not see how to apply that with the SQLinq NuGet package for Dapper.
using (var sqlCnn = base.GetConnection())
{
var viewData = sqlCnn.Query(from s in new SQLinq<Week_Returns_stats_V>(). . .
public SqlConnection GetConnection(bool mars = false)
{
if (_sqlCnn != null)
{
if (_sqlCnn.State != ConnectionState.Open) CloseConnection();
}
if (mars)
{
var scsb = new SqlConnectionStringBuilder(_cnnString)
{
MultipleActiveResultSets = true
};
}
_sqlCnn = new SqlConnection(_cnnString);
return _sqlCnn;
}
I found how to include buffered after the query.
public static IEnumerable<T> Query<T>
(this IDbConnection dbconnection,
SQLinq<T> query,
IDbTransaction transaction = null,
bool buffered = true,
int? commandTimeout = default(int?),
CommandType? commandType =
default(CommandType?)) where T : new();
var viewData = sqlCnn.Query(from s in new SQLinq<Returns_stats()
select new
{
AVGPercentReturnX100 = s.AVGPercentReturnX100,
PercentProfitableX100 = s.PercentProfitableX100
}, buffered:true).AsEnumerable()