public void CanCompareAnyField() { int n = 20; IEnumerable <TestObjString> cq = from i in Enumerable.Range(1, n) select new TestObjString { Data = Convert.ToString(i), Date = new DateTime(2013, 1, i) }; var db = new TestDb(TestPath.GetTempFileName()); db.InsertAll(cq); TableQuery <TestObjString> results = db.Table <TestObjString>().Where(o => o.Data.Equals("10")); Assert.AreEqual(results.Count(), 1); Assert.AreEqual(results.FirstOrDefault().Data, "10"); results = db.Table <TestObjString>().Where(o => o.Id.Equals(10)); Assert.AreEqual(results.Count(), 1); Assert.AreEqual(results.FirstOrDefault().Data, "10"); var date = new DateTime(2013, 1, 10); results = db.Table <TestObjString>().Where(o => o.Date.Equals(date)); Assert.AreEqual(results.Count(), 1); Assert.AreEqual(results.FirstOrDefault().Data, "10"); }
/// <summary> /// /// </summary> public void Delete(int id) { var user = users.FirstOrDefault(u => u.Id == id); if (user != null) { con.Delete(user); } }
public IEnumerator <T> GetEnumerator() { var lmt = tq.Limit; if (lmt != null) { for (var i = 0; i < lmt.Value; i++) { var el = tq.ElementAtOrDefault(i); if (el != null) { yield return(el); } else { break; } } } else { var el = tq.FirstOrDefault(); int i = 1; while (el != null) { yield return(el); el = tq.ElementAtOrDefault(i++); } } }
public ClientTable SelectClientTable(string UniqueHash) { TableQuery <ClientTable> query = connection.Table <ClientTable>().Where(cli => cli.UniqueHash.Equals(UniqueHash)); ClientTable table = query.FirstOrDefault(); return(table); }
public async Task DeleteTwoPastRemindersInFour() { List <Reminder> reminders = _ReminderDatasetProvider.GetListWithPastAndUpcomingReminders(); _databaseConnection.InsertAll(reminders, typeof(Reminder)); int numberOfDeletedReminders = await _reminderDataService.DeletePast(); TableQuery <Reminder> reminderTable = _databaseConnection.Table <Reminder>(); Reminder reminder2 = reminderTable.FirstOrDefault((x) => x.Title == "Title test 2"); Reminder reminder4 = reminderTable.FirstOrDefault((x) => x.Title == "Title test 4"); Assert.AreEqual(2, numberOfDeletedReminders); Assert.IsNotNull(reminder2); Assert.IsNotNull(reminder4); }
public Task <T> FirstOrDefaultAsync() { return(Task <T> .Factory.StartNew(() => { using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) { return _innerQuery.FirstOrDefault(); } })); }
public Secciones BuscarSeccion(int numero) { TableQuery <Secciones> consulta = from datos in cn.Table <Secciones>() where datos.Seccion == numero select datos; return(consulta.FirstOrDefault()); }
public TicketDatabase GetFirstTicket() { lock (_locker) { TableQuery <TicketDatabase> ticketsDatabase = DatabaseManager.Instance.GetTable <TicketDatabase>(); return(ticketsDatabase.FirstOrDefault()); } }
public Task <T> FirstOrDefaultAsync() { return(Task.Factory.StartNew(() => { using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) { return _innerQuery.FirstOrDefault(); } }, CancellationToken.None, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default)); }
public Locations GetLocationName(string uuid, int major, int minor) { var results = conn.Table <MMLocation>().Where(x => x.UUID == uuid && x.Major == major && x.Minor == minor); MMLocation resultMMLocation = results.FirstOrDefault(); int locationId = (resultMMLocation != null ? resultMMLocation.Id : 1); TableQuery <Locations> locationNameResult = conn.Table <Locations>().Where(x => x.Id == locationId); return(locationNameResult.FirstOrDefault()); }
public void Save(Note note) { note.LastModified = DateTime.Now.ToString(); if (notes.FirstOrDefault(n => n.Name == note.Name) != null) { database.Update(note); } else { database.Insert(note); } }
public Task <T> FirstOrDefaultAsync(CancellationToken cancellationToken = default(CancellationToken)) { return(Task.Factory.StartNew(() => { cancellationToken.ThrowIfCancellationRequested(); using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) { cancellationToken.ThrowIfCancellationRequested(); return _innerQuery.FirstOrDefault(); } }, cancellationToken, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default)); }
public void Save(Todo todo) { todo.LastModified = DateTime.Now.ToString(); if (todos.FirstOrDefault(t => t.Name == todo.Name) != null) { database.Update(todo); } else { database.Insert(todo); } }
public static Module.Module GetModule(Modules modulename) { try { using (SQLiteConnection dbConn = new SQLiteConnection(new SQLitePlatformWinRT(), path)) { TableQuery <ModuleTable> query = dbConn.Table <ModuleTable>(); return((Module.Module)deserializeModule(query.FirstOrDefault(module => module.ModuleName.Equals(modulename))?.ModuleConfig)); } } catch (Exception) { return(null); } }
#pragma warning disable 1998 public static async Task <string> GetModuleData(Modules modulename) #pragma warning restore 1998 { try { using (SQLiteConnection dbConn = new SQLiteConnection(new SQLitePlatformWinRT(), path)) { TableQuery <ModuleDataTable> query = dbConn.Table <ModuleDataTable>(); return(query.FirstOrDefault(module => module.ModuleName.Equals(modulename))?.ModuleData); } } catch (Exception) { return(null); } }
public static Module.Module GetModule(Modules modulename) { try { using (SQLiteConnection dbConn = new SQLiteConnection(new SQLitePlatformWinRT(), path)) { TableQuery <ModuleTable> query = dbConn.Table <ModuleTable>(); IEnumerable <ModuleTable> test = query.Select(x => x); string moduleString = query.FirstOrDefault(module => module.ModuleName.Equals(modulename))?.ModuleConfig; return((Module.Module)DeserializeModule(moduleString)); } } catch (Exception exception) { Log.Log.WriteException(exception); return(new Module.Module()); } }
/// <summary> /// Gets a client whit a specific policy /// </summary> /// <param name="policyId">the id of the policy</param> /// <returns>Returns a client or null if no record find</returns> public Client getClientByPolicy(string policyId) { Client clientResult = null; using (var conn = SqlLiteConnection(dbPath)) { try { TableQuery <Policy> policy = from s in conn.Table <Policy>() where s.id.Equals(policyId) select s; Policy poliyResult = policy.FirstOrDefault(); if (poliyResult != null) { clientResult = conn.Get <Client>(poliyResult.clientId); } } catch (Exception e) { log.Error("Error getClientByPolicy: " + e.Message); throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError); } } return(clientResult); }
/// <summary> /// Returns the first element of this query, or null if no element is found. /// </summary> public Task <T> FirstOrDefaultAsync() { return(ReadAsync(conn => _innerQuery.FirstOrDefault())); }