Exemple #1
0
        public Task <IEnumerable <T> > GetAll <T>() where T : MyScullion.Models.BaseModel, new()
        {
            CheckTable <T>();

            var myCollection = new List <T>();

            try
            {
                myCollection = base.Select <T>($"SELECT {ExtensionMethodsSQLiteRaw.PrepareFieldsToSelectOrInsert<T>()} FROM {typeof(T).Name}",
                                               ExtensionMethodsSQLiteRaw.SerializeCollection <T>);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }

            return(Task.FromResult <IEnumerable <T> >(myCollection));
        }
Exemple #2
0
        public Task <T> Get <T>(int id) where T : MyScullion.Models.BaseModel, new()
        {
            CheckTable <T>();

            try
            {
                var myT = base.SelectFirst <T>($"SELECT {ExtensionMethodsSQLiteRaw.PrepareFieldsToSelectOrInsert<T>()} FROM {typeof(T).Name} WHERE Id = @Id",
                                               new List <object>()
                {
                    new SqliteParameter("@Id", id)
                }, ExtensionMethodsSQLiteRaw.Serialize <T>);

                return(Task.FromResult(myT));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }

            return(Task.FromResult(default(T)));
        }