protected void LoadChildRecords(Type type) { using (SqlConnection conn = new SqlConnection(SQLDMGlobal.ConnectionString())) { conn.Open(); SqlCommand cmd = conn.CreateCommand(); try { foreach (DataLink dl in Links.FindAll(c => c.ChildRecordType == type)) { DataRecord childDummy = SQLDMGlobal.FindDummy(type); if (childDummy != null) { cmd.CommandText = string.Format("select * from {0} where [{1}] = {2}", childDummy.FullSafeTableName, dl.ChildFieldName, dl.ParentField.ParameterName); SqlParameter param = GetSqlParameter(dl.ParentField.ParameterName); if (param != null) { cmd.Parameters.Add(param); } SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataTable dt = new DataTable(); da.Fill(dt); foreach (DataRow row in dt.Rows) { DataRecord inst = (DataRecord)System.Activator.CreateInstance(dl.ChildRecordType); FillRecord(row, inst, true); ChildRecords.Add(inst); } cmd.Parameters.Clear(); } } } catch (Exception ex) { if (conn.State == ConnectionState.Open) { conn.Close(); } throw ex; } finally { conn.Close(); } } }
public Link[] GetLinks(string user = null, HashSet <string> guilds = null) { if (string.IsNullOrEmpty(user)) { if (guilds != null && guilds.Any()) { var arr = new BsonArray(); foreach (string guild in guilds) { arr.Add(guild); } return(Links .Find(Query.In("Guild", arr)) .OrderByDescending(l => l.PingId) .ToArray()); } else { return(Links .FindAll() .OrderByDescending(l => l.PingId) .ToArray()); } } else { if (guilds != null && guilds.Any()) { return(Links .Find(Query.EQ("User", user)) .Where(l => guilds.Contains(l.Guild)) .OrderByDescending(l => l.PingId) .ToArray()); } else { return(Links .Find(Query.EQ("User", user)) .OrderByDescending(l => l.PingId) .ToArray()); } } }