企业库缓存参数上存储的proc? [英] Enterprise library caching parameters on stored procs?

查看:81
本文介绍了企业库缓存参数上存储的proc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图与同事标准化一些数据访问代码。前面提到的一位同事断言EntLib数据访问块试图在存储的proc调用中缓存参数。

I'm trying to standardise some data access code with my colleagues. One of the aforementioned colleagues asserts that the EntLib Data Access Block trys to cache parameters on stored proc calls.

我看过反射器,有证据表明它可以将它们缓存起来。但是我不认为在以下情况下会这样做。

I've had a look in reflector and there is some evidence that it could be caching them. But I don't think it does in the following situation.

    public Dictionary<long, string> GetQueue(int maxItems)
    {
        var sq = new SqlDatabase(_connString.ConnectionString);

        var result = new Dictionary<long, string>();

        using (var cmd = (SqlCommand)sq.GetStoredProcCommand("dbo.GetQueue"))
        {
            sq.AddInParameter(cmd, "maxItems", DbType.Int32, maxItems);

            var reader =  cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (reader.Read())
            {
                long id = reader.GetInt64(reader.GetOrdinal("id"));
                string fileName = reader.GetString(reader.GetOrdinal("meta_data_filename"));

                result.Add(id, fileName);
            }
        }

        return result;
    }

有人可以确认或否认吗?

Can anyone confirm or deny this?

我使用的是EntLib 4.1

I'm using EntLib 4.1

推荐答案

它以前是很明确的,我将代码撕掉并放入

It definetly used to, I ripped the code out and threw in in my library.

它使用 sp_help 并解析输出以确定数据类型。

it used sp_help and parsed the output to determine the data types.

这些天,我撕掉了代码,.Net在添加参数方面要好得多。

These days, I ripped the code out, .Net is much much better about adding parameters.

cmd.Parameters.AddWithValue("@name",somevalue)

在您的示例中保持反射...您会发现它已沿着该路径完成GetStoredProcCommand()

in your example of you keep reflectoring ... you will find it being done down this path GetStoredProcCommand()

您将获得一个已经填充了参数的Command对象

You will get a Command object back, already populated with parameters

ent lib代码受版权保护,但是该代码与此几乎相同

The ent lib code is copyrighted, but the code is almost identical to this

http://code.google.com/p/dbdotnet/source/浏览/trunk/ParameterCache.cs

这篇关于企业库缓存参数上存储的proc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆