开发者

Is newest version of MS Enterprise Library compatible with older versions like 3.1

This current project I've been assigned uses the Version 3.1 levels of:

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

As I try to get to know more about the capabilities of the Ent Lib, I am running into lots of articles and doc about various versions (3.1, 4.0, and 5.0 I think).

In general do the newer versions work with application code written for an earlier release of the Ent Lib? I haven't surveyed all of the source code in this app I've inherited but I think only the "basics" of the Data Access Application Block are being used. Here is a typical piece of code:

        public override List<Erx.Action> GetAll(bool bIsActive)
    {
        Database db = null;
        DbCommand cmd = null;
        List<Erx.Action> lst = null;
        IDataReader iRdr = null;
        try
        {
            db = DatabaseFacto开发者_JAVA技巧ry.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;
    }

Frankly, this does not seem to offer much beyond regular ADO.Net but maybe the newer versions make things simpler (I've heard some very good stuff about Unity).


I just installed Ent Lib 4.1 and dug closely into the doc and found this in the "Introduction to the Data Access Application Block":

Changed Features, Version 3.1 and Later

In general, applications built using earlier releases of the Data Access Application Block will function with this release without the need for any code changes. It may be necessary to update the references to refer to the new assemblies and to update the configuration files to reference the correct version of the assemblies. However, some changes were made to the Data Access Application Block in version 3.1 (May 2007), which may affect applications written for earlier versions if you upgrade to the current version of Enterprise Library. The following sections describe these changes.

The .NET Framework 2.0 TransactionScope Class To take advantage of the .NET Framework 2.0 TransactionScope class, there have been changes to some of the Database class methods in version of Enterprise Library from version 3.1 onwards. These methods, such as ExecuteNonQuery, have been modified to recognize when a TransactionScope instance is active by replacing the GetConnection method with the GetOpenConnection method. If you have written a class that inherits from the Database class, you will need to rewrite your code to take these changes into account. If you continue to use the GetConnection method, you will receive a compiler warning. In addition, if your application uses the ExecuteXmlReader method, you may need to rewrite your code to test to see whether a TransactionScope instance is active before closing a connection. For more information, see Using the TransactionScope Class. For an example of how to use the ExecuteXMLReader method, see Retrieving Multiple Rows As XML. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜