using System; using System.Collections.Generic; using System.Text; using System.Configuration; namespace DashboardDataAccess { public static class DatabaseHelper { public const string ConnectionStringName = "DashboardConnectionString"; public const string ApplicationID = "fd639154-299a-4a9d-b273-69dc28eb6388"; public readonly static Guid ApplicationGuid = new Guid(ApplicationID); public static DashboardData GetDashboardData() { var db = new DashboardData(ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString); return db; } public static void Update<T>(T obj, Action<T> update) { var db = GetDashboardData(); db.GetTable<T>().Attach(obj); update(obj); db.SubmitChanges(); } public static void UpdateAll<T>(List<T> items, Action<T> update) { var db = GetDashboardData(); foreach( T item in items ) { db.GetTable<T>().Attach(item); update(item); } db.SubmitChanges(); } public static void Delete<T>(Action<T> makeTemplate) where T:new() { var db = GetDashboardData(); T template = new T(); makeTemplate(template); db.GetTable<T>().Remove(template); db.SubmitChanges(); } public static void Insert<T>(T obj) { var db = GetDashboardData(); db.GetTable<T>().Add(obj); db.SubmitChanges(); } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
The Next Version of Android - Some of What's Coming