/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/standard/data/sqlite/BatchingSample/Program.cs
71 строка
2 KB
Andy De George
Move snippets from samples repo to this repo (#17296)
03 мар 2020, 19:23
Не верифицирован
03 мар 2020, 19:23
dbbeda1
Код
Авторство
О чём код?
using System; using Microsoft.Data.Sqlite; namespace BatchingSample { class Program { static void Main() { var connection = new SqliteConnection("Data Source=:memory:"); connection.Open(); // SQLite doesn't support batching natively. Since there's no network involved, it // wouldn't really help with performance anyway. Batching is implemented in // Microsoft.Data.Sqlite as a convenience. For better command performance, see // BulkInsertSample. var createCommand = connection.CreateCommand(); createCommand.CommandText = @" CREATE TABLE blog ( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE post ( id INTEGER PRIMARY KEY, title TEXT, blog_id INTEGER NOT NULL, FOREIGN KEY (blog_id) REFERENCES blog ); INSERT INTO blog VALUES (1, 'Brice''s Blog'); INSERT INTO post VALUES (1, 'Hello, World!', 1), (2, 'SQLite on .NET Core', 1); "; createCommand.ExecuteNonQuery(); #region snippet_Batching // Batch two SELECT statements into a single command var command = connection.CreateCommand(); command.CommandText = @" SELECT * FROM blog; SELECT * FROM post; "; using (var reader = command.ExecuteReader()) { // Read the first result set while (reader.Read()) { Console.WriteLine($"Blog {reader["id"]}: {reader["name"]}"); } // Read the second result set reader.NextResult(); while (reader.Read()) { Console.WriteLine($"Post {reader["id"]}: {reader["title"]}"); } } #endregion } } }