public static CmdParameter CreateDataCountSql(ISessionImplementor session, IEntityPersister entityPersister, Criteria criteria) { var classMetadata = entityPersister.ClassMetadata; var result = new CmdParameter(); var parameters = new List<DbParameter>(); var sql = new StringBuilder(); sql.AppendFormat("SELECT COUNT(1) FROM {0} ", classMetadata.TableName); if (criteria != null && criteria.CriterionList != null && criteria.CriterionList.Count > 0) { criteria.Driver = entityPersister.Driver; criteria.DicParameter = entityPersister.GetParameter(session); criteria.DbParameter = parameters; sql.Append(" WHERE ").Append(criteria.ToString(classMetadata)); result.Parameters = parameters.ToArray(); } sql.Append(entityPersister.Driver.MultipleQueriesSeparator); result.CommandText = sql.ToString(); log.Info(sql); return result; }
public static CmdParameter CreateSelectSql2(ISessionImplementor session, IEntityPersister entityPersister, Criteria criteria, Order order) { var classMetadata = entityPersister.ClassMetadata; var result = new CmdParameter(); //if (string.IsNullOrEmpty(obj.Conditaion)) //{ // var columnInfo = classMetadata.ColumnInfos.Find(t => t.IsPrimaryKey); // if (columnInfo != null) // { // var v = columnInfo.PropertyInfo.FastGetValue(obj); // if (!IsNull(v)) result = CreateSelectSql(session, entityPersister, v); // } //} var parameters = new List<DbParameter>(); //entityPersister.Driver.FormatNameForSql(columnInfo.Name) // string rConditaion = GetConditaion(session, entityPersister, obj, out parameters); var sql = new StringBuilder("SELECT "); //sql.Append(string.IsNullOrEmpty(obj.ResultColumns) ? "*" : obj.ResultColumns); sql.Append("*"); sql.AppendFormat(" FROM {0} ", classMetadata.TableName); if (criteria != null && criteria.CriterionList != null && criteria.CriterionList.Count > 0) { criteria.Driver = entityPersister.Driver; criteria.DicParameter = entityPersister.GetParameter(session); criteria.DbParameter = parameters; sql.Append(" WHERE ").Append(criteria.ToString(classMetadata)); result.Parameters = parameters.ToArray(); } // entityPersister.SetDbParamter(session, parameters, columnInfo.Name, value); //var where = GetWhereCaluse(rConditaion); //if (where.Length > 0) //{ // sql.AppendFormat(" WHERE {0} ", where); // result.Parameters = parameters.ToArray(); //} //sql.Append(obj.OrderBy ?? "" ); sql.Append(order != null ? order.ToString(classMetadata) : ""); sql.Append(entityPersister.Driver.MultipleQueriesSeparator); result.CommandText = sql.ToString(); log.Info(sql); return result; }