Ejemplo n.º 1
0
        public TDataObject QuerySingleOrDefault <TDataObject>([NotNull] 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.ExecuteReader())
                    {
                        if (r.Read())
                        {
                            if (r.Read())
                            {
                                throw new InvalidOperationException("Too many objects");
                            }
                            return(DataObjectInfo <TDataObject> .Read(r));
                        }
                        return(default(TDataObject));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
                    }
                }
            }
        }