コード例 #1
0
ファイル: BaseSql.cs プロジェクト: dtrilsbeek/ShopNotch
        protected IEnumerable <TEntity> ExecuteQuery(SqlCommand command)
        {
            using (SqlConnection connection = new SqlConnection(_dbConfig.GetConnectionString()))
            {
                command.Connection = connection;
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    List <TEntity> items = new List <TEntity>();
                    while (reader.Read())
                    {
                        var item = CreateEntity();
                        Map(reader, item);
                        items.Add(item);
                    }

                    return(items);
                }
                finally
                {
                    reader.Close();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Return a new instance of DbProviderFactory created from dbConfig settings
        /// </summary>
        /// <param name="dbConfig"></param>
        /// <param name="withAdminPrivileges">If true, a DbProviderFactory with AdminConnectionString is build</param>
        /// <returns></returns>
        public static DbProviderFactory GetDbProviderFactory(this IDbConfig dbConfig, bool withAdminPrivileges = false)
        {
            var dbType = dbConfig.DbType;

            AssertDbProviderFactoryImplemented(dbType);
            var connectionString =
                withAdminPrivileges ? dbConfig.GetAdminConnectionString() : dbConfig.GetConnectionString();
            var dbProviderFactory = new FluentDbProviderFactory(DbProviderFactories[dbType], connectionString);

            return(dbProviderFactory);
        }