internal bool Exists(string modelName, string guid) { bool exists = true; try { using (MobeelizerDatabaseContext dataContext = new MobeelizerDatabaseContext(this.ConnectionString)) { var table = from MobeelizerWp7Model m in dataContext.GetTable(models[modelName].Type) where m.Guid == guid select m; table.Single(); } } catch (SystemException) { exists = false; } return(exists); }
internal MobeelizerOperationError UpdateEntitiesFromSync(IEnumerable <MobeelizerJsonEntity> entities, bool isAllSynchronization) { MobeelizerOperationError transactionErrors = null; using (MobeelizerDatabaseContext dataContext = new MobeelizerDatabaseContext(this.ConnectionString)) { if (isAllSynchronization) { foreach (var model in models.Values) { var table = dataContext.GetTable(model.Type); table.DeleteAllOnSubmit(from MobeelizerWp7Model record in table select record); } dataContext.ModelMetadata.DeleteAllOnSubmit(from m in dataContext.ModelMetadata select m); // TODO: check it //dataContext.Files.DeleteAllOnSubmit(from f in dataContext.Files select f); dataContext.SubmitChanges(); } foreach (MobeelizerJsonEntity entity in entities) { transactionErrors = models[entity.Model].UpdateFromSync(entity, dataContext); if (transactionErrors != null) { break; } } if (transactionErrors == null) { dataContext.SubmitChanges(); } } return(transactionErrors); }