diff --git a/README.md b/README.md index f05055dc..6980bd27 100644 --- a/README.md +++ b/README.md @@ -415,6 +415,32 @@ using (var connection = GetConnection(connectionString)) } ``` +#### 5. Dapper Query + +Thanks @shaofing #552 , please use `CommandDefinition + CommandFlags.NoCache` + +```csharp +using (var connection = GetConnection(connectionString)) +{ + var rows = connection.Query( + new CommandDefinition( + @"select 'MiniExcel' as Column1,1 as Column2 union all select 'Github',2" + , CommandFlags.NoCache) + ) + MiniExcel.SaveAs(path, rows); +} +``` + +Below code will load all data into memory + +```csharp +using (var connection = GetConnection(connectionString)) +{ + var rows = connection.Query(@"select 'MiniExcel' as Column1,1 as Column2 union all select 'Github',2"); + MiniExcel.SaveAs(path, rows); +} +``` + #### 6. SaveAs to MemoryStream [[Try it]](https://dotnetfiddle.net/JOen0e) diff --git a/README.zh-CN.md b/README.zh-CN.md index 183d283b..4100dbe2 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -415,7 +415,21 @@ MiniExcel.SaveAs(path, table); #### 5. Dapper Query -- `不推荐使用`,会将数据全载入内存,建议使用`ExecuteReader` +感谢 @shaofing #552 更正,低内存请使用 `CommandDefinition + CommandFlags.NoCache`,如下 + +```csharp +using (var connection = GetConnection(connectionString)) +{ + var rows = connection.Query( + new CommandDefinition( + @"select 'MiniExcel' as Column1,1 as Column2 union all select 'Github',2" + , CommandFlags.NoCache) + ) + MiniExcel.SaveAs(path, rows); +} +``` + +以下写法会将数据全载入内存 ```csharp using (var connection = GetConnection(connectionString)) diff --git a/README.zh-Hant.md b/README.zh-Hant.md index 5b694c13..0b4beebd 100644 --- a/README.zh-Hant.md +++ b/README.zh-Hant.md @@ -409,7 +409,21 @@ MiniExcel.SaveAs(path, table); #### 5. Dapper Query -- `不推薦使用`,會將數據全載入Memory,建議使用`ExecuteReader` +感謝 @shaofing #552 更正,低內存請使用 `CommandDefinition + CommandFlags.NoCache`,如下 + +```csharp +using (var connection = GetConnection(connectionString)) +{ + var rows = connection.Query( + new CommandDefinition( + @"select 'MiniExcel' as Column1,1 as Column2 union all select 'Github',2" + , CommandFlags.NoCache) + ) + MiniExcel.SaveAs(path, rows); +} +``` + +以下寫法會將數據全載入內存 ```csharp using (var connection = GetConnection(connectionString))