// ==================================================================== // IDE 生成イベントハンドラー // ==================================================================== private void ButtonCreate_Click(object sender, EventArgs e) { try { DeleteExistDatabase(DB_NAME_BASIC); Console.WriteLine("DB を作成します..."); using (SQLiteConnection aConnection = CreateDatabaseConnection(DB_NAME_BASIC)) using (SQLiteCommand aCmd = new SQLiteCommand(aConnection)) { // ユニーク制約 List <String> aUniques = new List <String>(); aUniques.Add("test_name"); // テーブル作成 LinqUtils.CreateTable(aCmd, typeof(TTestData), aUniques); // インデックス作成 List <String> aIndices = new List <String>(); aIndices.Add("test_name"); aIndices.Add("test_height"); LinqUtils.CreateIndex(aCmd, LinqUtils.TableName(typeof(TTestData)), aIndices); // データ挿入 using (DataContext aContext = new DataContext(aConnection)) { Table <TTestData> aTableTest = aContext.GetTable <TTestData>(); aTableTest.InsertOnSubmit(new TTestData { Id = 1, Name = "Fukada Kyoko" }); aTableTest.InsertOnSubmit(new TTestData { Id = 2, Name = "Eda Ha", Height = 180.0 }); aTableTest.InsertOnSubmit(new TTestData { Id = 3, Name = "Dan Gerou", Height = 150.5 }); aTableTest.InsertOnSubmit(new TTestData { Id = 4, Name = "Baba Takashi" }); aTableTest.InsertOnSubmit(new TTestData { Id = 5, Name = "Aikawa Ai", Height = 145.6 }); aContext.SubmitChanges(); Console.WriteLine("DB にテーブルを作成しました。件数:" + aTableTest.Count().ToString()); } } } catch (Exception oExcep) { Console.WriteLine(oExcep.Message); } }
private void ButtonCreate2_Click(object sender, EventArgs e) { try { DeleteExistDatabase(DB_NAME_GENERIC); Console.WriteLine("DB を作成します..."); using (SQLiteConnection aConnection = CreateDatabaseConnection(DB_NAME_GENERIC)) using (SQLiteCommand aCmd = new SQLiteCommand(aConnection)) { // フルーツテーブル作成 LinqUtils.CreateTable(aCmd, typeof(TFruitData)); // データ挿入 using (DataContext aContext = new DataContext(aConnection)) { Table <TFruitData> aTableTest = aContext.GetTable <TFruitData>(); aTableTest.InsertOnSubmit(new TFruitData { Id = 1, Name = "Apple", Color = "Red" }); aTableTest.InsertOnSubmit(new TFruitData { Id = 2, Name = "Banana", Color = "Yellow" }); aTableTest.InsertOnSubmit(new TFruitData { Id = 3, Name = "Strawberry", Color = "Red" }); aTableTest.InsertOnSubmit(new TFruitData { Id = 4, Name = "Orange", Color = "Orange" }); aTableTest.InsertOnSubmit(new TFruitData { Id = 5, Name = "Grape" }); aContext.SubmitChanges(); Console.WriteLine("DB にフルーツテーブルを作成しました。件数:" + aTableTest.Count().ToString()); } // 肉テーブル作成 LinqUtils.CreateTable(aCmd, typeof(TMeatData)); // データ挿入 using (DataContext aContext = new DataContext(aConnection)) { Table <TMeatData> aTableTest = aContext.GetTable <TMeatData>(); aTableTest.InsertOnSubmit(new TMeatData { Id = 1, Name = "Pork" }); aTableTest.InsertOnSubmit(new TMeatData { Id = 2, Name = "Beef", Cooking = "Burger" }); aTableTest.InsertOnSubmit(new TMeatData { Id = 3, Name = "Chicken", Cooking = "Fried chicken" }); aContext.SubmitChanges(); Console.WriteLine("DB に肉テーブルを作成しました。件数:" + aTableTest.Count().ToString()); } } } catch (Exception oExcep) { Console.WriteLine(oExcep.Message); } }