0

我被分配的这个当前项目使用 3.1 版本的级别:

Microsoft.Practices.EnterpriseLibrary.Common;
Microsoft.Practices.EnterpriseLibrary.Data;

当我尝试更多地了解 Ent Lib 的功能时,我遇到了很多关于各种版本(我认为是 3.1、4.0 和 5.0)的文章和文档。

一般来说,较新的版本是否适用于为早期版本的 Ent Lib 编写的应用程序代码?我没有调查我继承的这个应用程序中的所有源代码,但我认为只有数据访问应用程序块的“基础”被使用。这是一段典型的代码:

        public override List<Erx.Action> GetAll(bool bIsActive)
    {
        Database db = null;
        DbCommand cmd = null;
        List<Erx.Action> lst = null;
        IDataReader iRdr = null;
        try
        {
            db = DatabaseFactory.CreateDatabase();
            cmd = db.GetStoredProcCommand("Mst_GetAllCorrectiveAction");
            db.AddInParameter(cmd, "@CorrectiveActionID", DbType.Int32, -1);
            db.AddInParameter(cmd, "@IsActive", DbType.Boolean, bIsActive);
            iRdr = db.ExecuteReader(cmd);

            lst = new List<Erx.Action>();

            while (iRdr.Read())
            {
                Action objAction = new Action();
                objAction.CorrectiveAction = iRdr["CorrectiveAction"].ToString();
                objAction.CorrectiveActionID = int.Parse(iRdr["CorrectiveActionID"].ToString());
                objAction.IsActive = (bool)iRdr["IsActive"];
                lst.Add(objAction);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            db = null;
            iRdr.Close();
            if (cmd != null)
            {
                cmd.Dispose(); cmd = null;
            }
        }
        return lst;
    }

坦率地说,这似乎并没有提供超出常规 ADO.Net 的功能,但也许较新的版本使事情变得更简单(我听说过一些关于 Unity 的非常好的东西)。

4

2 回答 2

1

我刚刚安装了 Ent Lib 4.1 并仔细研究了文档,并在“数据访问应用程序块简介”中找到了这一点:

更改的功能,版本 3.1 及更高版本

通常,使用早期版本的数据访问应用程序块构建的应用程序将在此版本中运行,而无需更改任何代码。可能需要更新引用以引用新程序集,并更新配置文件以引用正确版本的程序集。但是,在版本 3.1(2007 年 5 月)中对数据访问应用程序块进行了一些更改,如果您升级到当前版本的企业库,这可能会影响为早期版本编写的应用程序。以下部分描述了这些更改。

.NET Framework 2.0 TransactionScope 类 为了利用 .NET Framework 2.0 TransactionScope 类,从 3.1 版开始,Enterprise Library 版本中的一些 Database 类方法发生了更改。这些方法(例如 ExecuteNonQuery)已修改为通过将 GetConnection 方法替换为 GetOpenConnection 方法来识别 TransactionScope 实例何时处于活动状态。如果您编写了一个继承自 Database 类的类,则需要重写代码以将这些更改考虑在内。如果您继续使用 GetConnection 方法,您将收到编译器警告。此外,如果您的应用程序使用 ExecuteXmlReader 方法,您可能需要重写代码以测试在关闭连接之前查看 TransactionScope 实例是否处于活动状态。有关更多信息,请参阅使用 TransactionScope 类。 strong text SQL Server Compact Edition Enterprise Library 3.1 – May 2007 and later supports SQL Server Compact Edition (CE). SQL Server CE provides the essential features of a relational database and is intended for desktop and mobile applications that need a local data store but do not require the full functionality of SQL Server. For more information, see the section "Using SQL Server CE" in Creating a Database Object.

I am still trying to get a sense of how truly useful this DAAB is. It seems like a tremendous amount of reading of doc is required to end up writing just a little less code than otherwise required with ADO.NET un-aided by the DAAB. I guess if one wanted to provide for an easier switch to say, Oracle [from MS SQL Server), this is a useful way to configure things.

于 2009-12-22T19:59:20.050 回答
0

If you have unit tests,port to new and run and see,if you have Resharper it can analyse your solution in VStudio and point out the errors.It will take you time.

于 2009-12-28T15:01:21.580 回答