private SqlCommand GetCommand(SqlConnection cn, T t, IContext context, ModelActionOption option) { SqlCommand cmd = null; var found = _Model.ModelActions.Find(x => x.Verb.Equals(option)); if (found == null) { XF.Common.Discovery.SqlTable table = null; if (SprocMapCache.Instance.TryGetTable <T>(context, cn, out table)) { cmd = XF.Common.Discovery.InlineSqlCommandGenerator.Generate <T>(cn, table, option, t); } } else { cmd = cn.CreateCommand(); XF.Common.Db.DbCommand dbCmd = null; var foundAction = _Model.ModelActions.Find(x => x.Verb.Equals(option)); if (foundAction != null) { dbCmd = _Model.Commands.Find(x => x.Key.Equals(foundAction.DbCommandKey, StringComparison.OrdinalIgnoreCase)); } if (dbCmd != null) { cmd.CommandType = ConvertCommandType(dbCmd.CommandType); cmd.CommandText = dbCmd.CommandText; AddParameters(cmd, dbCmd.Parameters, t, context); } } return(cmd); }
private SqlCommand GetCommand(SqlConnection cn, ICriterion criterion, IContext context, ModelActionOption option) { SqlCommand cmd = null; var found = _Model.ModelActions.Find(x => x.Verb.Equals(option)); if (found != null) { XF.Common.Db.DbCommand dbCmd = null; if (criterion != null && criterion.ContainsStrategy() && found.Switches != null) { var foundCase = found.Switches[0].Cases.Find(x => x.Value.Equals(criterion.GetStrategyKey())); if (foundCase != null) { dbCmd = _Model.Commands.Find(x => x.Key.Equals(foundCase.CommandKey, StringComparison.OrdinalIgnoreCase)); } } else { var foundAction = _Model.ModelActions.Find(x => x.Verb.Equals(option)); if (foundAction != null && _Model.Commands != null) { dbCmd = _Model.Commands.Find(x => x.Key.Equals(foundAction.DbCommandKey, StringComparison.OrdinalIgnoreCase)); } } if (dbCmd != null) { cmd = cn.CreateCommand(); cmd.CommandType = ConvertCommandType(dbCmd.CommandType); cmd.CommandText = dbCmd.CommandText; AddParameters(cmd, dbCmd.Parameters, criterion, context); } } if (cmd == null) { XF.Common.Discovery.SqlTable table = null; if (SprocMapCache.Instance.TryGetTable <T>(context, cn, out table)) { cmd = XF.Common.Discovery.InlineSqlCommandGenerator.Generate(cn, table, option, criterion); } } return(cmd); }