diff --git a/Database.cs b/Database.cs index f901b71..ea63cae 100644 --- a/Database.cs +++ b/Database.cs @@ -10,16 +10,9 @@ namespace it_projekt { class Database : DbContext { - public DbSet persons { get; set; } - - public Database() - : base() - { - - - } - public Database(DbConnection existingConnection, bool contextOwnsConnection) - : base(existingConnection, contextOwnsConnection) + public virtual DbSet persons { get; set; } + public Database(String connectionString) + : base(connectionString) { } diff --git a/Form1.cs b/Form1.cs index 1662c79..51dcf2b 100644 --- a/Form1.cs +++ b/Form1.cs @@ -34,45 +34,9 @@ namespace it_projekt public static void LoadUsersFromTable(string user, string password) { - string connectionString = "server=localhost;port=3306;database=stammdaten;User Id=" + user + ";Password=" + password + ";"; - - using (MySqlConnection connection = new MySqlConnection(connectionString)) - { - // Create database if not exists - using (Database contextDB = new Database(connection, false)) - { - contextDB.Database.CreateIfNotExists(); - } - - connection.Open(); - MySqlTransaction transaction = connection.BeginTransaction(); - - try - { - // DbConnection that is already opened - using (Database context = new Database(connection, false)) - { - - // Interception/SQL logging - context.Database.Log = (string message) => { Console.WriteLine(message); }; - - // Passing an existing transaction to the context - context.Database.UseTransaction(transaction); - - // DbSet.AddRange - List persons = new List(); - persons = context.persons.ToList(); - - } - - transaction.Commit(); - } - catch - { - transaction.Rollback(); - throw; - } - } + string connectionString = "server=localhost;database=stammdaten;User Id=" + user + ";Password=" + password + ";"; + Database test = new Database(connectionString); + MessageBox.Show(test.persons.Find(1).Firstname); } diff --git a/it-projekt.csproj b/it-projekt.csproj index b5e4aec..1c42316 100644 --- a/it-projekt.csproj +++ b/it-projekt.csproj @@ -10,6 +10,7 @@ + \ No newline at end of file