/// <summary> /// Get an entity from the database /// </summary> /// <param name="keyValues">Key-columns from the entity/table</param> /// <returns>An entity if founds, otherwise null</returns> async public static Task <T> Get(params object[] keyValues) { using (var ctx = new KaigangDbContext()) { return(await ctx.FindAsync <T>(keyValues)); } }
public void TearDown() { using (var ctx = new KaigangDbContext()) { ctx.Database.ExecuteSqlCommand("TRUNCATE TABLE Pages;"); } }
/// <summary> /// Returns a list of entities based on an expresion /// </summary> /// <param name="ft">The expressiont to query the Database</param> /// <returns>A list with the entities found</returns> async public static Task <IEnumerable <T> > GetMany(Func <T, bool> ft) { return(await Task.Run(() => { using (var ctx = new KaigangDbContext()) { return ctx.Set <T>().Where(ft).ToList(); } })); }
/// <summary> /// Deletes and Entity /// </summary> /// <param name="entity">Entity to be removed from database</param> /// <returns>Operation successfull or not</returns> async public static Task <bool> Delete(T entity) { using (var ctx = new KaigangDbContext()) { ctx.Remove <T>(entity); var res = await ctx.SaveChangesAsync(); return(res > 0); } }
/// <summary> /// Inserts an entity into the Database /// </summary> /// <param name="entity">Entity to be inserted</param> /// <returns>The saved entity</returns> async public static Task <T> Add(T entity) { using (var ctx = new KaigangDbContext()) { await ctx.AddAsync <T>(entity); await ctx.SaveChangesAsync(); return(entity); } }
public void SetUp() { using (var ctx = new KaigangDbContext()) { var _page = new Page() { Content = _content, Name = _name }; ctx.Add <Page>(_page); ctx.SaveChanges(); id = _page.ID; } }