internal static async Task <long> GetCountAsync <T>(Expression <Func <T, bool> > predicate) where T : class { return(await Task.Run <long>(() => { using (var provider = new SqliteDataProvider(StorePath)) { using (var context = new Vx.Context(provider)) { return context.DataSet <T>().Where(predicate).Count(); } } }).ConfigureAwait(false)); }
private static async Task <List <T> > SearchAsync <T>(Expression <Func <T, bool> > searchCriteria, int take, int skip) where T : class { return(await Task.Run <List <T> >(() => { using (var provider = new SqliteDataProvider(StorePath)) { using (var context = new Vx.Context(provider)) { return context.DataSet <T>().Take(take).Skip(skip).ToList(); } } }).ConfigureAwait(false)); }
private static async Task <List <T> > ReadBatchAsync <T>(int count, params Expression <Func <T, object> >[] relationsToLoad) where T : class { return(await Task.Run <List <T> >(() => { using (var provider = new SqliteDataProvider(StorePath)) { using (var context = new Vx.Context(provider)) { return context.DataSet <T>().WithRelations(relationsToLoad).Take(count).ToList(); } } }).ConfigureAwait(false)); }
private static async Task <T> FirstOrDefaultAsync <T>(Expression <Func <T, bool> > predicate , bool recursive = false) where T : class { return(await Task.Run <T>(() => { using (var provider = new SqliteDataProvider(StorePath)) { using (var context = new Vx.Context(provider)) { return context.DataSet <T>().FirstOrDefault(predicate); } } }).ConfigureAwait(false)); }
internal static async Task <ChatConversation> GetConversationFromThreadingInfoAsync(ChatConversationThreadingInfo threadingInfo) { return(await Task.Run <ChatConversation>(() => { using (var provider = new SqliteDataProvider(StorePath)) { using (var context = new Vx.Context(provider)) { var q = from conversation in context.DataSet <ChatConversation>() where conversation.Id == threadingInfo.Id select conversation; return q.FirstOrDefault(); } } }).ConfigureAwait(false)); }
internal static async Task MarkMessagesAsSeenAsync() { await Task.Run(() => { using (var provider = new SqliteDataProvider(StorePath)) { using (var context = new Vx.Context(provider)) { var q = from message in context.DataSet <ChatMessage>() where !message.IsSeen select message; foreach (var message in q) { message.IsSeen = true; context.Update(message); } } } }).ConfigureAwait(false); }