示例#1
0
        /// <summary>
        /// Find the first / only object that matches the given criteria.
        /// </summary>
        /// <typeparam name="TInIdentity">Type of object used to identity the domain object desired.</typeparam>
        /// <param name="selectionFactory">Factory object that can turn
        /// the identity object into the appropriate DbCommand.</param>
        /// <param name="domainObjectFactory">Factory object that can turn the
        /// returned result set into a domain object.</param>
        /// <param name="identity">Object that identifies which item to get.</param>
        /// <returns>The domain object requested, or null if not found.</returns>
        public TDomainObject FindOne <TInIdentity, TOutIdentity>(
            IIOSelectionFactory <TInIdentity, TOutIdentity> selectionFactory,
            IDomainObjectFactory <TDomainObject> domainObjectFactory,
            TInIdentity inIdentity,
            ref TOutIdentity outIdentity
            )
        {
            TDomainObject result = default(TDomainObject);

            using (DbCommand command = selectionFactory.ConstructSelectCommand(db, inIdentity, outIdentity))
            {
                using (IDataReader rdr = db.ExecuteReader(command))
                {
                    if (rdr.Read())
                    {
                        result = domainObjectFactory.Construct(rdr);
                    }
                }
                selectionFactory.PopulateOutValues(db, command, ref outIdentity);
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Find all objects that match the given criteria.
        /// </summary>
        /// <typeparam name="TInIdentity">Type of object used to identify
        /// the objects to find.</typeparam>
        /// <param name="selectionFactory">Factory object that can turn the
        /// identity object into the appropriate DbCommand.</param>
        /// <param name="domainObjectFactory">Factory object that can turn the
        /// returned result set into a domain object.</param>
        /// <param name="identity">Object that identifies which items to get.</param>
        /// <returns></returns>
        public List <TDomainObject> Find <TInIdentity, TOutIdentity>(
            IIOSelectionFactory <TInIdentity, TOutIdentity> selectionFactory,
            IDomainObjectFactory <TDomainObject> domainObjectFactory,
            TInIdentity inIdentity,
            ref TOutIdentity outIdentity
            )
        {
            List <TDomainObject> results = new List <TDomainObject>();

            using (DbCommand command = selectionFactory.ConstructSelectCommand(db, inIdentity, outIdentity))
            {
                using (IDataReader rdr = db.ExecuteReader(command))
                {
                    while (rdr.Read())
                    {
                        results.Add(domainObjectFactory.Construct(rdr));
                    }
                }

                selectionFactory.PopulateOutValues(db, command, ref outIdentity);
            }
            return(results);
        }