public void Load(Database db) { if (!_loaded) { lock (_loadLock) { if (!_loaded) { XrefsByListId = new Dictionary <long, X>(); QuerySet q = Dao.GetQuerySet(db); q.Select <X>().Where(new AssignValue(ParentColumnName, Parent.IdValue, q.ColumnNameFormatter)); q.Execute(db); // should have all the ids of L that should be retrieved if (q.Results[0].DataTable.Rows.Count > 0) { List <long> ids = new List <long>(); foreach (DataRow row in q.Results[0].DataTable.Rows) { long id = Convert.ToInt64(row[ListColumnName]); ids.Add(id); X xref = new X(); xref.DataRow = row; XrefsByListId.Add(id, xref); } QuerySet q2 = Dao.GetQuerySet(db); QueryFilter filter = new QueryFilter(Dao.GetKeyColumnName <L>()); filter.In(ids.ToArray(), db.ParameterPrefix); q2.Select <L>().Where(filter); q2.Execute(db); Initialize(q2.Results[0].DataTable, db); } _loaded = true; } } } }
private X EnsureXref(L item, Database db = null) { db = db ?? Database; if (item.IdValue != null && XrefsByListId.ContainsKey(item.IdValue.Value)) { return(XrefsByListId[item.IdValue.Value]); } else { if (item.IsNew) { item.Save(db); } X result = null; QuerySet q = Dao.GetQuerySet(db); q.Select <X>().Where(new QueryFilter(ListColumnName) == item.IdValue.Value && new QueryFilter(ParentColumnName) == Parent.IdValue); q.Execute(db); if (q.Results[0].DataTable.Rows.Count > 0) { result = new X(); result.DataRow = q.Results[0].DataTable.Rows[0]; } else { result = new X(); result.SetValue(string.Format("{0}Id", Parent.GetType().Name), Parent.IdValue); result.SetValue(string.Format("{0}Id", typeof(L).Name), item.IdValue); result.Save(db); XrefsByListId.Add(item.IdValue.Value, result); } return(result); } }