Enterprise Library DAAB, Use it, or Not?

Enterprise Library DAAB, Use it, or Not?

Old forum URL: forums.lhotka.net/forums/t/1025.aspx


secovel posted on Friday, August 25, 2006

I've seen Rocky's post that Enterprise Library can compliment CSLA.  That's good!  I need a bigger question answered.  SHOULD I use the DAAB with CSLA?  If the answer is yes, how would one go about doing it?  Has anybody used the DAAB with CSLA, and would you share that experience with me?

Thanks,

Sean

Ashraf Ali replied on Friday, August 25, 2006

I started the thread "presentation and data access layer frameworks" (Take a look at that too)

and I tried to find someone who would share their experiences with us regarding CSLA and Enterprise integration. So far the folks who have replied didn't  enjoy enterprise library with CSLA ( especially if your DBMS is only one type like SQLServer), Personally I dont like Enterprise library dataaccess block or DAAB because of its dependency on Datasets (it probably stems from the fact that I am not a big fan of datasets when it comes down to using them in business layer or even data access layer).

Ash

 

Brent replied on Saturday, August 26, 2006

The DAAB works great with CSLA in my experience (that's our only pattern).  You need to separate your DAL in a separate assembly if you really want to get the benefits of DAAB when using CSLA.  If you're dealing with transactions, there is a issue at the moment about how to move the transactions to the server but Rocky has mentioned that he may have a possible solution for that problem (LocalContext).

In my experience, CSLA does nothing but compliment the enterprise library and vice versa.

 P.S. I never use datasets in any case, the IDataReader interface from the DAL works well with SafeDataReader.

 

Brent

simon_may replied on Saturday, August 26, 2006

Surely the first question should be: does the DAAB help me meet my requirements? That is, what is it that using the DAAB solves that I can't solve without it or something similar.No point in using it just for its own sake.

secovel replied on Saturday, August 26, 2006

simon_may:
Surely the first question should be: does the DAAB help me meet my requirements? That is, what is it that using the DAAB solves that I can't solve without it or something similar.No point in using it just for its own sake.


Simon,

Sometimes the requirement that you fullfill is that you support all of the buzzwords that managment is looking for... :-( 

"The app needs to be Scalable and Robust.  Shouldn't we be using the Enterprise Library?  What's that DAAB everyone is talking about.  Shouldn't we be using that?"

The chances that an app will ever get "ported" to another DB is pretty slim.  Sounds like Rocky's CSLA already takes care of the 3-tier requirement.  Probably don't need it at all.  What else is it good for? 

Sean

simon_may replied on Sunday, August 27, 2006

Sean

Good point. Thankfully, I have been out of that type of environment for a while now and, silly me, I forgot about those types of requirements.

So let me rephrase my response. The DAAB is a brilliant addition to your technical Marketecture, it performs exremely well on all powerpoint slides and in most meetings with senior management patrticularly when they have recently returned a drop of Microsoft hospitality ;-)

Simon

secovel replied on Sunday, August 27, 2006

OMG!  I almost shot milk out my nose!  And I wasn't even drinking milk!

Sean

secovel replied on Saturday, August 26, 2006

Brent,

Thanks!  That gives me something to look into.

Sean

lprada replied on Monday, August 28, 2006

I use EntLib. Great Integration. Here is a Fetch Example.

 

 private void DataPortal_Fetch(Criteria criteria) {
            Microsoft.Practices.EnterpriseLibrary.Data.Database PMDatabase = DatabaseFactory.CreateDatabase("PM");
            try {

                using (DbCommand dbCommand = PMDatabase.GetStoredProcCommand("GetProject")) {
                    PMDatabase.AddInParameter(dbCommand, "guid", DbType.Guid, criteria.Id);

                    using (SafeDataReader dr = new SafeDataReader(PMDatabase.ExecuteReader(dbCommand))) {
                        dr.Read();
                        _id = dr.GetGuid("guid");
                        _internalCode = dr.GetString("internalcode");
                        _comercialName = dr.GetString("comercialname");
                        _internalName = dr.GetString("internalname");
                        _description = dr.GetString("description");
                        _started = dr.GetSmartDate("started", _started.EmptyIsMin);
                        _ended = dr.GetSmartDate("ended", _ended.EmptyIsMin);
                        dr.GetBytes("lastchanged", 0, _timestamp, 0, 8);
                        _isInactive = dr.GetBoolean("isdeleted");
                    }
                }


            }
            catch {
                throw;
            }
        }

Ashraf Ali replied on Monday, August 28, 2006

sweet! Can you please give a short example where you update the database ( I mean Insert, Update operation)

Thanks

Ash

Ashraf Ali replied on Wednesday, August 30, 2006

Oh Oh! No one is interested anymore ???

FireGarden replied on Wednesday, August 30, 2006

Come on Ash! Download the DAAB and read the help file. It will show you how to do an insert. Its really not much differnt than the above example.

 Personally I really enjoy the Enterprise Library and think you will too.

Rob

Ashraf Ali replied on Thursday, August 31, 2006

FireGarden! I know that DAAP hands on lab and documentation show how to use its methods, what I was looking for its usage with CSLA, if you look at the post by Bob hagan, he is using db.excecutenonquery,

I thought how could we possibly use db.updatedataset with CSLA?

I hope I have cleared myself

 

Ash

thomasjrr replied on Wednesday, February 14, 2007

Ash,

  I modified the CSLAContrib CodeSmith templates to use the Jan 06 Enterprise Library.  It is just a start (transactions not solved), but it might get you started.  The reason we are using the EL is that we are developing COTS software and we want to be able to support Oracle and MS Sql Server.  So far, testing has progressed well.  If you are interested in the templates, please e-mail me.

robert.thomas@capricciosoftware.com

Bob

DavidDilworth replied on Monday, March 12, 2007

FWIW, we originally started with a DAL that integrated with the DAAB.  It worked fine, but we were still writing a bunch of SQL Stored Procedure code.

Then we discovered NHibernate and decided to use that instead because:

(1) It gives the potential for cross database portability (SQL Server, Oracle, MySQL are our target database engines).

(2) You don't have to write any SQL Stored Procedures - NHibernate does all the SQL for you.

(3) You can use attributes to mark up your class code giving you potential benefits with code generation techniques.

At the end of the day, you need to pick the tools that get the job done.  Either technology will do a good job, so you need to pick the one that best suits your needs.

HTH

bobhagan replied on Thursday, August 31, 2006

It might not be quite as simple as it seems.  
Des Nolan mentioned in another thread about dals, that the biggest benefit for this is when you have an application that has to use more than one data source.  I'm using Oracle and some SQL Server, so I experimented with the 1.1 version.

There are some real differences in calling stored procedures etc between the two databases.  The code above calls a stored procedure in SQL Server format.  Oracle frequently combines sps into a "package" with the format "Project.GetProject".  Oracle also must use a "RefCursor" to return values in a fetch.  Because of these seemingly minor differences, for at least some things you need to create a separate dal with a provider for each database you are supporting.

I was able to make a dynamic query/update work, but then disovered that there was a bug in the way the Oracle provider handled parameters.  There was a patch created later, but I gave up, because I had no need to support different dbs in the same application.   I use CodeSmith templates and it was relatively easy to modify them so you could generate the dataportal code for the correct db. 

This is the old style dataportal code modified

if(this.IsNew)
 {
     //perform an insert, object has not been persisted
     if(System.Configuration.ConfigurationSettings.AppSettings["DBType"] == "ORA" )
     {   
    db.ExecuteNonQuery(tr,CommandType.Text,OraQueries.Client_Insert(CLIENT_ID,CLIENT_NM, blah) );
else
    //Insert to SQLServer

OraQueries had:

public static string Gen_id(IDbTransaction tr, Database db)
        {
            //Not using an SP, so get the Ora Sequence
            DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("PRC_GEN_ID");
            dbCommandWrapper.AddOutParameter("OUT_ID", DbType.String, 16);
            db.ExecuteNonQuery(dbCommandWrapper, tr);
            string GEN_ID = dbCommandWrapper.GetParameterValue("Out_ID").ToString();
            return GEN_ID ;
        }

public static string Client_Insert( string CLIENT_NM, blah)
{
   string CLIENT_ID = Queries.Gen_id(tr, db);
   string SQL = "INSERT INTO CLIENT " + 
                    "(CLIENT_ID,CLIENT_NM, blah) " + 
                    "VALUES ('" + CLIENT_ID + "','"+ CLIENT_NM +"','"+ blah ))";
  return SQL;
}

There are additional commands to handle parameters, but I couldn't get them to work.
I discovered on gotdotnet that there was a bug, that was later patched.

dbCommandWrapper.AddInParameter("p_CLIENT_ID", DbType.String, CLIENT_ID);
DBCommandWrapper dbCommandWrapper = db.GetSqlStringCommandWrapper();
Client_parameters(dbCommandWrapper,  )
then the query. 
there is a similar Command Wrapper to call a stored procedure.
(I noticed in my code that I also called the Gen_id function from the dataportal and passed the value back the the query, so that was not generic.  I just moved the call to the OraQueries section - I haven't tested this)

Hope that helps

I have a couple of questions, as well:

1) Has anyone tried the EntLib with Oracle in VS2.0?  Are the problems I described above fixed?
2) I've also been unable to use Oracle stored procedures in VS 2.0 becasue it appears that the MS Oracle provider no longer supports RefCursors.  I posted a question on this on the ASP.NET site, but only got a reply from the woman who also thought that csla was going to be integrated into the Enterprise Library.   What she said was that support for RefCursors was dropped from the Microsoft Oracle Provider and to change to the Oracle built Oracle provider.  Say what?

Bob Hagan

ajj3085 replied on Thursday, August 31, 2006

bobhagan:
What she said was that support for RefCursors was dropped from the Microsoft Oracle Provider and to change to the Oracle built Oracle provider.  Say what?


Well this part I think means that you should use the Oracle created .Net managed provider, not the one MS ships with the framework.

Frankly I'd rather use the managed provider from Oracle anyway.. MS's version likely is out of date and slower (kind of like the default video drivers; they work, but you're better off getting the ones from NVidia).

Copyright (c) Marimer LLC