This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

Extension ID

com.castsoftware.msenterpriselibrary

What's new?

See Microsoft Enterprise Library - 1.0 - Release Notes for more information.

Description

This extension provides support for Microsoft Enterprise Library APIs (see Methods Supported) which are responsible for typical CRUD operations with the database.

In what situation should you install this extension?

If your C# application performs SQL queries with the Microsoft Enterprise Library framework, and you want to modelize the Client/Server links with appropriate objects and links, then you should use this extension.

Technology support

Item

Version

Supported

Supported Technology

Notes

MS Enterprise Library2.0 to 6.0.1304(tick)C#See https://www.nuget.org/packages/EnterpriseLibrary.Data
MS Enterprise Library SqlCe5.0 to 6.0.1304 (tick)C#See https://www.nuget.org/packages/EnterpriseLibrary.Data.SqlCe

AIP Core compatibility

AIP Core release

Supported

8.3.x(tick)

Supported DBMS servers

DBMS

Supported

CSS/PostgreSQL      (tick)

Download and installation instructions

For applications using Microsoft Enterprise Library APIs, the extension will be automatically installed by CAST Console. This is in place since October 2023.

For upgrade, if the Extension Strategy is not set to Auto update, you can manually install the extension using the Application - Extensions interface.

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner. The following objects and  links will be displayed in CAST Imaging:

Objects

The following objects are created by this extension and displayed in CAST Enlighten:

Icon

Type Description

When is this objectcreated ?

DotNet Enterprise Library SQL Queryan object is created for each SQL query found and resolved in a MS EntLib CRUD method call

Links created by this extension and other related extensions

Link Type

Caller type

Callee type

Methods Supported
callLinkC# MethodDotNet Enterprise Library SQL Query
Click here to expand...
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.UpdateDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.BeginExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.BeginExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.BeginExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteXmlReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.LoadDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.UpdateDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.BeginExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.BeginExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.BeginExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.BeginExecuteXmlReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.DoExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.ExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.ExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.ExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.ExecuteDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.LoadDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.UpdateDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.BeginExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.BeginExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.BeginExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.DoExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.ExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.ExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.ExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.ExecuteDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.LoadDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.UpdateDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase.DoExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteNonQuery
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteNonQuerySql
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteScalar
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteScalarSql
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteResultSet
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.DoExecuteResultSet
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteReader
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteReaderSql
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.ExecuteDataSetSql
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.LoadDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.UpdateDataSet
  • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase.DoExecuteNonQuery
useLinkDotNet Enterprise Library SQL QueryTable, ViewCreated by SQL Analyzer when DDL source files are analyzed
callLinkDotNet Enterprise Library SQL QueryProcedure
useLinkDotNet Enterprise Library SQL QueryMissing TableCreated by Missing tables and procedures for .Net extension when the object is not analyzed.
callLinkDotNet Enterprise Library SQL QueryMissing Procedure

Example code scenarios

ExecuteNonQuery

ExecuteNonQuery
ExecuteNonQuery
public void RecordIsInsertedWhenExecutingExecuteReaderWithTransactionStoredProcParamsAndCallBack()
        {
            Database db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DbCommand command1 = new SqlCommand();
            AsyncCallback cb = new AsyncCallback(EndExecuteReaderCallBack);
            DbAsyncState state;
            DbTransaction transaction;
            DataTable dt = new DataTable();
            object[] paramsArray = { "BONAP" };

            DataSet ds = db.ExecuteDataSet("CustOrdersOrders", paramsArray);
            int originalCount = ds.Tables[0].Rows.Count;
            try
            {
                using (SqlConnection connection = new SqlConnection(db.ConnectionString))
                {
                    connection.Open();
                    transaction = connection.BeginTransaction();

                    // Execute the NonQuery insert statement synchronously.                    
                    command1.CommandType = CommandType.Text;
                    command1.CommandText = @"INSERT INTO [Northwind].[dbo].[Orders]
                                                   ([CustomerID]
                                                   ,[EmployeeID]
                                                   ,[OrderDate]
                                                   ,[RequiredDate]
                                                   ,[ShippedDate]
                                                   ,[ShipVia]
                                                   ,[Freight]
                                                   ,[ShipName]
                                                   ,[ShipAddress]
                                                   ,[ShipCity]
                                                   ,[ShipRegion]
                                                   ,[ShipPostalCode]
                                                   ,[ShipCountry])
                                             VALUES
                                                   ('BONAP'
                                                   ,1
                                                   ,GETDATE()
                                                   ,GETDATE()
                                                   ,NULL
                                                   ,2
                                                   ,10
                                                   ,'TestShip'
                                                   ,'TestShip address'
                                                   ,'Marseille'
                                                   ,NULL
                                                   ,'13008'
                                                   ,'France')";
                    db.ExecuteNonQuery(command1, transaction);
					// Get the records using overloaded BeginExecuteReader with stored proc and params Asynchronously with DBTransaction.                                        
                    state = BeginExecuteReader(db, "CustOrdersOrders", transaction, cb, paramsArray);
                    dt.Load((IDataReader)state.State);

                    transaction.Commit();

                    Assert.AreEqual<int>(originalCount + 1, dt.Rows.Count);
                    Assert.AreEqual<ConnectionState>(ConnectionState.Open, state.AsyncResult.Connection.State);
                }
            }

ExecuteNonQuery Example
public string UpdateSC(SubComponentSavedInfo UpdateSCObject, string LoginID, Int64 DisputeID, int UpdateID)
        {
            string strSPNm = "dbo.dt3_web_UpdateSC";
            string NewUpdateID = "";
            using (DbCommand ObjDbCommand = objDB.GetStoredProcCommand(strSPNm))
            {
                objDB.AddInParameter(ObjDbCommand, "@LoginID", DbType.String, LoginID);
                objDB.AddInParameter(ObjDbCommand, "@LeadDisputeID", DbType.Int64, DisputeID);
                objDB.AddInParameter(ObjDbCommand, "@SCStatusInd", DbType.String, UpdateSCObject.SCStatusInd);
                objDB.AddInParameter(ObjDbCommand, "@DisputeSubCompID", DbType.Int32, UpdateSCObject.SubCompID);
                objDB.AddInParameter(ObjDbCommand, "@ResolutionCode", DbType.String, UpdateSCObject.ResolutionCode);
                objDB.AddInParameter(ObjDbCommand, "@RFDCode", DbType.String, UpdateSCObject.RFDCode);
                objDB.AddInParameter(ObjDbCommand, "@RCCode", DbType.String, UpdateSCObject.RCCode);

                objDB.AddInParameter(ObjDbCommand, "@AdjClassCode", DbType.String, UpdateSCObject.AdjClassCode);
                objDB.AddInParameter(ObjDbCommand, "@SpecialRemarks", DbType.String, UpdateSCObject.ReasonForAdjK4);
                objDB.AddInParameter(ObjDbCommand, "@AdjHow", DbType.String, UpdateSCObject.AdjHow);
                objDB.AddInParameter(ObjDbCommand, "@FirstCallDate", DbType.String, UpdateSCObject.FirstCallDate);
                objDB.AddInParameter(ObjDbCommand, "@LastCallDate", DbType.String, UpdateSCObject.LastCallDate);
                objDB.AddInParameter(ObjDbCommand, "@FirstBillDate", DbType.String, UpdateSCObject.FirstBillDate);
                objDB.AddInParameter(ObjDbCommand, "@LastBillDate", DbType.String, UpdateSCObject.LastBillDate);
                objDB.AddInParameter(ObjDbCommand, "@ServiceID", DbType.Int32, UpdateSCObject.ServiceID);
                objDB.AddInParameter(ObjDbCommand, "@EstimatedAdjAmt", DbType.Decimal, Convert.ToDecimal(UpdateSCObject.TotalEstAdjAmt));
                objDB.AddInParameter(ObjDbCommand, "@ManualAdjAmt", DbType.Decimal, Convert.ToDecimal(UpdateSCObject.TotalManualAdjAmt));
                objDB.AddInParameter(ObjDbCommand, "@DupDisputeID", DbType.Int64, UpdateSCObject.DupDisputeID);
                objDB.AddInParameter(ObjDbCommand, "@ProblemDescription", DbType.String, UpdateSCObject.ProbelDesc);
                objDB.AddInParameter(ObjDbCommand, "@DiscDeskTrackNum", DbType.String, UpdateSCObject.DiskDeskTrackNo);
                objDB.AddInParameter(ObjDbCommand, "@BillingReferralFormNum", DbType.String, UpdateSCObject.BillingRefferalFormNo);
                objDB.AddInParameter(ObjDbCommand, "@ActualSOAdjAmt", DbType.Decimal, Convert.ToDecimal(UpdateSCObject.ActualSOAdjAmt));
                objDB.AddInParameter(ObjDbCommand, "@SODueDate", DbType.String, UpdateSCObject.SODueDate);
                objDB.AddInParameter(ObjDbCommand, "@SOFollowUpDate", DbType.String, UpdateSCObject.SOFollowUpDate);
                objDB.AddInParameter(ObjDbCommand, "@FollowUpInvDate", DbType.String, UpdateSCObject.SOFollowUpInvDate);

                objDB.AddInParameter(ObjDbCommand, "@SONo", DbType.String, UpdateSCObject.SoNo);
                objDB.AddInParameter(ObjDbCommand, "@SOEBD", DbType.String, UpdateSCObject.SoEBD);
                objDB.AddInParameter(ObjDbCommand, "@ChkSOFollowUpDate", DbType.String, UpdateSCObject.ChkSoFollowUpDate);
                objDB.AddInParameter(ObjDbCommand, "@ChkSOBilledDate", DbType.String, UpdateSCObject.ChkSOBilledDate);
                objDB.AddInParameter(ObjDbCommand, "@SpiritAdjustmentURL", DbType.String, UpdateSCObject.SpiritAdjUrl);
                objDB.AddInParameter(ObjDbCommand, "@DeMinimisInd", DbType.String, UpdateSCObject.DeminimisInd);
                objDB.AddInParameter(ObjDbCommand, "@DisputeTypeInd", DbType.String, UpdateSCObject.DisputeTypeInd);
                objDB.AddInParameter(ObjDbCommand, "@UpdateID", DbType.Int32, UpdateID);
                objDB.AddOutParameter(ObjDbCommand, "@NewUpdateID", DbType.String, Int32.MaxValue);
                objDB.ExecuteNonQuery(ObjDbCommand);
                NewUpdateID = Convert.ToString(objDB.GetParameterValue(ObjDbCommand, "NewUpdateID"));
            }
            return NewUpdateID;
        }

ExecuteReader

ExecuteReader
ExecuteReader
public void ValuesAreReadWhenUsingInnerReader()
       	 {
            Database db = DatabaseFactory.CreateDatabase("OracleTest");
            const string sqlCommand = "select * from Customers where customerId ='BLAUS'";
            DbCommand dbCommandWrapper = db.GetSqlStringCommand(sqlCommand);
            //IDataReader dataReader = db.ExecuteReader(CommandType.Text, sqlCommand);
            using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
            {
                using (OracleDataReader orareader = ((OracleDataReaderWrapper)dataReader).InnerReader)
                {
                    Assert.IsNotNull(orareader);
                    int n = orareader.GetOrdinal("customerId");
                    while (dataReader.Read())
                    {
                        string str1 = orareader.GetOracleValue(n).ToString();
                        string str = ((string)dataReader[0]).Trim();
                        Assert.AreNotSame(str1, str);
                    }
                }
            }
        }
  

ExecuteScalar

ExecuteScalar
ExecuteScalar
public void AllRecordsAreReturnedWhenExecutingExecuteXmlReaderWithSqlCommandAndWithCallBack()
        {
            DbAsyncState state;
            DataTable dt = new DataTable();
            DbCommand command = new SqlCommand();
            DbCommand command1 = new SqlCommand();
            AsyncCallback cb = new AsyncCallback(EndExecuteXmlReaderCallBack);
            int rowCount = 0;
            SqlDatabase db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync") as SqlDatabase;

            //Get the row count synchronously.
            command1.CommandType = CommandType.Text;
            command1.CommandText = "SELECT count(*) FROM Employees";
            int originalCount = (int)db.ExecuteScalar(command1);

            // Get the data Asynchronously.
            command.CommandType = CommandType.Text;
            command.CommandText = "SELECT * FROM Employees FOR XML AUTO, XMLDATA";
            state = BeginExecuteXmlReader(db, command, cb);

        }

ExecuteDataSet

ExecuteDataSet
ExecuteDataSet
public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessor()
        {
            Database db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor<TopTenProduct> accessor = db.CreateSprocAccessor<TopTenProduct>("Ten Most Expensive Products");
            AsyncCallback cb = new AsyncCallback(EndExecuteAccessor<TopTenProduct>);
            DbAsyncState state = new DbAsyncState(db, accessor);
            IAsyncResult result = accessor.BeginExecute(cb, state);
            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable<TopTenProduct> resultSet = (IEnumerable<TopTenProduct>)state.State;

            object[] paramsArray = { };
            DataSet ds = db.ExecuteDataSet("Ten Most Expensive Products", paramsArray);
            Assert.IsNull(state.Exception);
            Assert.AreEqual<int>(ds.Tables[0].Rows.Count, resultSet.Count());
        }

UpdateDataSet

UpdateDataSet
UpdateDataSet
public void TestUpdateDatasetMethod()
        {
            SqlCeDatabase db = (SqlCeDatabase)database;
			DataSet dataSet = new DataSet();
            db.UpdateDataSet(dataSet, "Region", "insert into region values (99, 'Midwest')", "UPDATE region SET RegionDescription=@RegionDescription WHERE RegionID=@RegionId",
                                 "Delete from Region where RegionId = 99", "Incremental");
        }
   

ExecuteXmlReader

ExecuteXmlReader
ExecuteXmlReader
public void CanExecuteXmlQueryThroughTransaction()
        {
            string insertString = "insert into region values (99, 'Midwest')";
            DbCommand insertCommand = sqlDatabase.GetSqlStringCommand(insertString);

            string queryString = "Select * from Region for xml auto";
            SqlCommand sqlCommand = sqlDatabase.GetSqlStringCommand(queryString) as SqlCommand;

            string actualOutput = "";

            using (DbConnection connection = sqlDatabase.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    sqlDatabase.ExecuteNonQuery(insertCommand, transaction.Transaction);

                    XmlReader results = sqlDatabase.ExecuteXmlReader(sqlCommand, transaction.Transaction);
                    results.MoveToContent();
                    for (string value = results.ReadOuterXml(); value != null && value.Length != 0; value = results.ReadOuterXml())
                    {
                        actualOutput += value;
                    }
                    results.Close();
                }
            }
            
        }

BeginExecuteReader

BeginExecuteReader
BeginExecuteReader
protected override void Act()
        {
            var asyncResult = database.BeginExecuteReader("Ten Most Expensive Products", null, null);
            var reader = database.EndExecuteReader(asyncResult);
            reader.Dispose();
        }

BeginExecuteScalar

BeginExecuteScalar
BeginExecuteScalar
public class WhenAsynchronouslyInvokingExecuteScalarOnSproc : AsynchronousConnectionContext
    {
        IAsyncResult asyncResult;

        protected override void Arrange()
        {
            base.Arrange();

            asyncResult = database.BeginExecuteScalar("Ten Most Expensive Products", null, null);
        }
}

BeginExecuteNonQuery

BeginExecuteNonQuery
BeginExecuteNonQuery
public class WhenAsynchronouslyInvokingBeginExecuteNonQueryOnSproc : AsynchronousConnectionContext
    {
        IAsyncResult asyncResult;

        protected override void Arrange()
        {
            base.Arrange();

            asyncResult = database.BeginExecuteNonQuery("Ten Most Expensive Products", null, null);
        }
	}

BeginExecuteXmlReader

BeginExecuteXmlReader
BeginExecuteXmlReader
public class WhenAsynchronouslyInvokingExecuteXmlReader : AsynchronousConnectionContext
    {
        private readonly Barrier barrier = new Barrier(2);
        private XmlReader reader;

        protected override void Arrange()
        {
            base.Arrange();

            string queryString = "Select * from Region for xml auto, xmldata";
            SqlCommand sqlCommand = database.GetSqlStringCommand(queryString) as SqlCommand;
            database.BeginExecuteXmlReader(sqlCommand,
                ar =>
                {
                    barrier.Await();
                    reader = database.EndExecuteXmlReader(ar);
                    barrier.Await();
                }, null);
        }

DoExecuteNonQuery

DoExecuteNonQuery
DoExecuteNonQuery
public static void DoExecuteResultSetOracleSample(Database db)
        {
            
            db.DoExecuteNonQuery("insert into Region values (99, 'Midwest');");
        }

LoadDataSet

LoadDataSet
LoadDataSet
public static void LoadTestData(Database database)
        {
            SqlCeDatabase db = (SqlCeDatabase)database;

            db.LoadDataSet("insert into Region values (99, 'Midwest');");
        }

ExecuteScalarSql

ExecuteScalarSql
ExecuteScalarSql
public void SimplifiedExecuteScalarWithParameters()
	{
		string sql = "select count(*) from region where regionId=" + db.BuildParameterName("regionId");
		int result = (int)db.ExecuteScalarSql(sql, db.CreateParameter("regionId", DbType.Int32, 0, 2));
		Assert.AreEqual(1, result);
	}

ExecuteNonQuerySql

ExecuteNonQuerySql
ExecuteNonQuerySql
public void AlternateSqlStatementWithParameters()
        {
            string sql = "insert into region values ({0}, {1})";
            sql = String.Format(sql, db.BuildParameterName("regionId"), db.BuildParameterName("description"));

            DbParameter[] parameters = new DbParameter[]
                {
                    db.CreateParameter("regionId", DbType.Int32, 0, 99),
                    db.CreateParameter("description", DbType.String, 20, "test value")
                };
            db.ExecuteNonQuerySql(sql, parameters);
        }

Limitations

  • Objects will not be created if evaluation fails to resolve the necessary parameter.
  • The set of supported methods is limited to what is documented.
  • The support works when the Microsoft Enterprise Library is used directly, that is, not through a custom wrapper delivered as an assembly.