SQLite Queries for Xamarin.Forms

  public class LocalDB
    {
        private SQLiteConnection _sqlconnection;

        public LocalDB()
        {
            //Getting conection and Creating table 
            _sqlconnection = DependencyService.Get<ISQLite>().GetConnection();
            _sqlconnection.CreateTable<LocationModel>();
        }

        //Get all
        public IEnumerable<LocationModel> GetAllLocation()
        {
            return (from t in _sqlconnection.Table<LocationModel>() select t).ToList();
        }

        //Get specific 
        //public LocationModel GetSingleLocation(int id)
        //{
        //    return _sqlconnection.Table<LocationModel>().FirstOrDefault(t => t.Id == id);
        //}

        //Delete specific
        public void DeleteLocation(int id)
        {
            _sqlconnection.Delete<LocationModel>(id);
        }

        //Add new to DB 
        public void AddLocation(LocationModel location)
        {
            _sqlconnection.Insert(location);
        }
    }

Comments

Popular posts from this blog

Listview SelectedItem in MVVM

Button click event with current object from listview having button

SideMenu React native