Line | |
---|
1 | using System;
|
---|
2 |
|
---|
3 | namespace 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.