public IList <TDataObject> Load <TDataObject>(IList <int> ids) where TDataObject : class, IIntKeyedDataObject, new() { // TODO: Try to get needed objects from Cache first if (ids.Count == 0) { return(new TDataObject[0]); } using (var scope = DBScope("Loading multiple " + typeof(TDataObject).Name + ". Count = " + ids.Count)) { using (var cmd = scope.Connection.CreateCommand()) { List <TDataObject> result; cmd.CommandText = DataObjectInfo <TDataObject> .SelectSql + " WHERE (ID IN (" + ids.ConcatComma() + ")) AND sysState = 0"; using (var r = cmd.LexExecuteReader()) { result = DataObjectInfo <TDataObject> .FullRead(r, ids.Count); } if (result.Count != ids.Count) { throw new DMError("Count of populated objects ({0}) lower than requested to extract {1}", result.Count, ids.Count); } foreach (var o in result) { Logger.WriteLine("ID = " + o.ID); CacheIt(o); } return(result); } } }
public List <TDataObject> Query <TDataObject>([CanBeNull] IDBPredicate cond) where TDataObject : IDataObject, new() { using (var scope = DBScope("Custom query for " + typeof(TDataObject))) { using (var c = scope.Connection.CreateCommand()) { var sc = new SqlSerializationContext(c); DataObjectInfo <TDataObject> .AppendQuerySql(sc, cond); sc.Finish(); using (var r = c.LexExecuteReader()) { var res = DataObjectInfo <TDataObject> .FullRead(r, 1); if (typeof(TDataObject).GetInterface(typeof(IIntKeyedDataObject).Name) != null) { // TODO: Cache them // foreach (var i in res) // { // CacheIt<TDataObject>(i as IIntKeyedDataObject); // } } return(res); } } } }
public IList <TDataObject> Load <TDataObject>(IList <int> ids) where TDataObject : class, IIntKeyedDataObject, new() { // TODO: Try to get needed objects from Cache first if (ids.Count == 0) { return(new TDataObject[0]); } using (var scope = DBScope(Translations.DatabaseModel_Load_Loading_multiple_ + typeof(TDataObject).Name + Translations.DatabaseModel_Insert_ + ids.Count)) { using (var cmd = scope.Connection.CreateCommand()) { List <TDataObject> result; cmd.CommandText = DataObjectInfo <TDataObject> .SelectSql + " WHERE (ID IN (" + ids.ConcatComma() + ")) AND sysState = 0"; using (var r = cmd.LexExecuteReader()) { result = DataObjectInfo <TDataObject> .FullRead(r, ids.Count); } if (result.Count != ids.Count) { throw new DMError(Translations.DatabaseModel_Load_Count_of_populated_objects___0___lower_than_requested_to_extract__1_, result.Count, ids.Count); } foreach (var o in result) { Logger.WriteLine("ID = " + o.ID); CacheIt(o); } return(result); } } }