private void CompileViews() { var hasher = new SqlSourceHasher(); if (!_dbModel.Driver.Supports(DbFeatures.Views)) { return; } var views = _dbModel.Tables.Where(t => t.Kind == EntityKind.View).ToList(); var engine = new Vita.Data.Linq.Translation.LinqEngine(_dbModel); foreach (var viewTbl in views) { var translatedCmd = engine.Translate(viewTbl.Entity.ViewDefinition.Command); viewTbl.ViewHash = hasher.ComputeHash(translatedCmd.Sql); viewTbl.ViewSql = hasher.GetHashLine(viewTbl.ViewHash) + Environment.NewLine + translatedCmd.Sql; //Save hash in DbVersionInfo var hashKey = DbModel.GetViewKey(viewTbl); _dbModel.VersionInfo.Values[hashKey] = viewTbl.ViewHash; } }
// Looks up SQL query in query cache; if not found, builds SqlQuery object and saves in cache. private TranslatedLinqCommand GetTranslateLinqCommand(LinqCommand command) { var cmdInfo = command.Info; //Lookup in cache SQL query or build it var translCmd = this.DbModel.QueryCache.Lookup(cmdInfo.CacheKey); if (translCmd != null) { return(translCmd); } //Build sqlQuery if not found var engine = new Vita.Data.Linq.Translation.LinqEngine(this.DbModel); translCmd = engine.Translate(command); // save in cache var canCache = !cmdInfo.Options.IsSet(QueryOptions.NoQueryCache) && !translCmd.Flags.IsSet(LinqCommandFlags.NoQueryCache); if (canCache) { DbModel.QueryCache.Add(cmdInfo.CacheKey, translCmd); } return(translCmd); }
private void AddScheduledCommands(IList <ScheduledLinqCommand> commands) { if (commands.Count == 0) { return; } var entModel = _db.DbModel.EntityApp.Model; var engine = new Vita.Data.Linq.Translation.LinqEngine(_db.DbModel); object[] fmtArgs = new object[100]; //specifics of formatting stored proc call - the first 2 args are always two braces // Braces in string literals are escaped and are represented as '{0}' and '{1}' fmtArgs[0] = "{"; fmtArgs[1] = "}"; foreach (var schCmd in commands) { CheckCurrentCommand(); var dbCmd = _currentCommand.DbCommand; var linqCmd = schCmd.Command; LinqCommandAnalyzer.Analyze(entModel, linqCmd); var transCmd = engine.Translate(linqCmd); for (int prmIndex = 0; prmIndex < transCmd.Parameters.Count; prmIndex++) { var linqParam = transCmd.Parameters[prmIndex]; var value = linqParam.ReadValue(linqCmd.ParameterValues) ?? DBNull.Value; var dbParam = dbCmd.CreateParameter(); _db.DbModel.LinqSqlProvider.SetDbParameterValue(dbParam, linqParam.Type, value); var globalParamIndex = dbCmd.Parameters.Count; dbParam.ParameterName = _driver.DynamicSqlParameterPrefix + "P" + globalParamIndex; fmtArgs[prmIndex + 2] = dbParam.ParameterName; dbCmd.Parameters.Add(dbParam); } var sql = string.Format(transCmd.BatchSqlTemplate, fmtArgs); _sqlBuilder.AppendLine(sql); }//foreach schCmd }
// Looks up SQL query in query cache; if not found, builds SqlQuery object and saves in cache. private TranslatedLinqCommand GetTranslateLinqCommand(LinqCommand command) { var cmdInfo = command.Info; //Lookup in cache SQL query or build it var translCmd = this.DbModel.QueryCache.Lookup(cmdInfo.CacheKey); if(translCmd != null) return translCmd; //Build sqlQuery if not found var engine = new Vita.Data.Linq.Translation.LinqEngine(this.DbModel); translCmd = engine.Translate(command); // save in cache var canCache = !cmdInfo.Options.IsSet(QueryOptions.NoQueryCache) && !translCmd.Flags.IsSet(LinqCommandFlags.NoQueryCache); if (canCache) DbModel.QueryCache.Add(cmdInfo.CacheKey, translCmd); return translCmd; }
private void CompileViews() { var hasher = new SqlSourceHasher(); if (!_dbModel.Driver.Supports(DbFeatures.Views)) return; var views = _dbModel.Tables.Where(t => t.Kind == EntityKind.View).ToList(); var engine = new Vita.Data.Linq.Translation.LinqEngine(_dbModel); foreach(var viewTbl in views) { var translatedCmd = engine.Translate(viewTbl.Entity.ViewDefinition.Command); viewTbl.ViewHash = hasher.ComputeHash(translatedCmd.Sql); viewTbl.ViewSql = hasher.GetHashLine(viewTbl.ViewHash) + Environment.NewLine + translatedCmd.Sql; //Save hash in DbVersionInfo var hashKey = DbModel.GetViewKey(viewTbl); _dbModel.VersionInfo.Values[hashKey] = viewTbl.ViewHash; } }
private void AddScheduledCommands(IList<ScheduledLinqCommand> commands) { if (commands.Count == 0) return; var entModel = _db.DbModel.EntityApp.Model; var engine = new Vita.Data.Linq.Translation.LinqEngine(_db.DbModel); object[] fmtArgs = new object[100]; //specifics of formatting stored proc call - the first 2 args are always two braces // Braces in string literals are escaped and are represented as '{0}' and '{1}' fmtArgs[0] = "{"; fmtArgs[1] = "}"; foreach (var schCmd in commands) { CheckCurrentCommand(); var dbCmd = _currentCommand.DbCommand; var linqCmd = schCmd.Command; LinqCommandAnalyzer.Analyze(entModel, linqCmd); var transCmd = engine.Translate(linqCmd); for (int prmIndex = 0; prmIndex < transCmd.Parameters.Count; prmIndex++) { var linqParam = transCmd.Parameters[prmIndex]; var value = linqParam.ReadValue(linqCmd.ParameterValues) ?? DBNull.Value; var dbParam = dbCmd.CreateParameter(); _db.DbModel.LinqSqlProvider.SetDbParameterValue(dbParam, value); var globalParamIndex = dbCmd.Parameters.Count; dbParam.ParameterName = _driver.DynamicSqlParameterPrefix + "P" + globalParamIndex; fmtArgs[prmIndex + 2] = dbParam.ParameterName; dbCmd.Parameters.Add(dbParam); } var sql = string.Format(transCmd.BatchSqlTemplate, fmtArgs); _sqlBuilder.AppendLine(sql); }//foreach schCmd }