public double SumAsDouble(string attrDefName) { double count = 0; var sql = SqlQueryBuilder.Build(DataContext, Def); sql.AddAttribute(attrDefName, SqlQuerySummaryFunction.Sum); using (var reader = new SqlQueryReader(DataContext, sql)) { reader.Open(); if (reader.Read()) { if (!reader.IsDbNull(0)) { if (reader.Reader.GetFieldType(0) == typeof(double)) { count = reader.GetDouble(0); } else if (reader.Reader.GetFieldType(0) == typeof(decimal)) { count = (double)reader.GetDecimal(0); } } } reader.Close(); } return(count); }
public List <T> All <T>(string attrDefName) { var list = new List <T>(); var sql = SqlQueryBuilder.Build(DataContext, Def); sql.AddAttribute(attrDefName); using (var reader = new SqlQueryReader(DataContext, sql)) { reader.Open(); while (reader.Read()) { if (!reader.IsDbNull(0)) { T item; var v = reader.GetValue(0); list.Add(v.TryParse(out item) ? item : default(T)); } else { list.Add(default(T)); } } reader.Close(); } return(list); }
public SqlQueryMasterSlaveLink AddMasterLink(SqlQueryReader master, string masterAttrName, string paramName) { var link = new SqlQueryMasterSlaveLink(Query, masterAttrName, paramName); _masterLinks.Add(link, master); return(link); }
public DataTable All() { var sql = SqlQueryBuilder.Build(DataContext, Def); var table = new DataTable(sql.Source.AliasName); using (var reader = new SqlQueryReader(DataContext, sql)) { table.Load(reader.Reader); } return(table); }
public T Sum <T>(string attrDefName) { var result = default(T); using (var reader = new SqlQueryReader(DataContext, Query)) { var v = reader.GetSum(attrDefName); if (v != null) { v.TryParse(out result); } } return(result); }
public void Update(SqlQueryReader masterSource) { if (!masterSource.Active) { return; } var masterFieldIndex = MasterAttributeId != Guid.Empty ? masterSource.TryGetAttributeIndex(MasterAttributeId) : masterSource.TryGetAttributeIndex(MasterAttributeName); if (masterFieldIndex >= 0) { Slave.SetParams(SlaveParamName, masterSource.GetValue(masterFieldIndex)); } }
public int Count() { var count = 0; var sql = SqlQueryBuilder.Build(DataContext, Def); sql.AddAttribute("&Id", SqlQuerySummaryFunction.Count); using (var reader = new SqlQueryReader(DataContext, sql)) { reader.Open(); if (reader.Read()) { if (!reader.IsDbNull(0)) { count = reader.GetInt32(0); } } reader.Close(); } return(count); }
public T Sum <T>(string attrDefName) { T result = default(T); var sql = SqlQueryBuilder.Build(DataContext, Def); sql.AddAttribute(attrDefName, SqlQuerySummaryFunction.Sum); using (var reader = new SqlQueryReader(DataContext, sql)) { reader.Open(); if (reader.Read()) { if (!reader.IsDbNull(0)) { var v = reader.GetValue(0); v.TryParse(out result); } } reader.Close(); } return(result); }
public object Min(string attrDefName) { using (var reader = new SqlQueryReader(DataContext, Query)) return(reader.GetMin(attrDefName)); }
public object Min(Guid attrDefId) { using (var reader = new SqlQueryReader(DataContext, Query)) return(reader.GetMin(attrDefId)); }
public int Count() { using (var reader = new SqlQueryReader(DataContext, Query)) return(reader.GetCount()); }