2016-10-04 39 views
0

我正在使用Dapper与SQLinq Nuget packageDapper&SQLinq包延迟/缓冲区

这是我使用的一些示例代码。

在运行.ToList()(例如)之前,用SQLinq进行查询运行查询。

我知道Dapper,你可以指定“缓冲区”来使它延迟运行,但是我没有看到如何将这个应用到Dapper的SQLinq NuGet包中。

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; 
} 

回答

0

我发现如何在查询后包含缓冲区。

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()