Пример #1
0
 /// <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));
     }
 }
Пример #2
0
 public void TearDown()
 {
     using (var ctx = new KaigangDbContext())
     {
         ctx.Database.ExecuteSqlCommand("TRUNCATE TABLE Pages;");
     }
 }
Пример #3
0
 /// <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();
         }
     }));
 }
Пример #4
0
        /// <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);
            }
        }
Пример #5
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);
            }
        }
Пример #6
0
 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;
     }
 }