Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Services.Authentication Prototype/Persistence/DatabaseUtil.cs @ 3966

Last change on this file since 3966 was 3955, checked in by bfarka, 14 years ago

created impl and test of AddUsersToRoles (#1046)

File size: 1.1 KB
Line 
1using System;
2
3namespace Persistence {
4  /// <summary>
5  /// combines multiple used static methods into one class
6  /// </summary>
7  public class DatabaseUtil {
8    /// <summary>
9    /// creates and returns a database connection, if possible
10    /// </summary>
11    /// <returns>database connection (could be null)</returns>
12    public static DataClassesDataContext createDataClassesDataContext() {
13        return  new Persistence.DataClassesDataContext(@"C:\TEMP\HeuristicLabTest.mdf");
14    }
15
16    /// <summary>
17    /// creates a new database out of the LINQ to SQL classes
18    /// </summary>
19    /// <param name="db">DataClassesDataContext</param>
20    public static void createDatabase(DataClassesDataContext db) {
21      if (db == null) {
22        throw new ArgumentNullException("db");
23      }
24     
25      if (db.DatabaseExists()) {
26        Console.WriteLine("Deleting old database...");
27        db.DeleteDatabase();
28        Console.WriteLine("Deleted old database!");
29      }
30
31      Console.WriteLine("Creating new database...");
32      db.CreateDatabase();
33      Console.WriteLine("Created new database!");
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.