Dofactory.com
Dofactory.com
 Back to list
Views:   9.9K
Replies:  2
Archived

What is the purpose of the Take Method in the Patterns In action ADO.NET data access layer?

Hello, I've just recently purchased the design patterns framework.  So far it's looking really good.  I'm only just starting to look around it.  

I'm reading the Getting Started 4.0 PDF at the moment. I got to "Step 3: Detail Level" where I started looking at the Data Objects project.  so far most of it makes sense but I noticed a method named Take() that I cannot find any use. The code attached is from the SqlServerProductDao.cs file.

The method is simple but I was just curious if anyone can tell me why it is there?  The same method is used in all of the ADO.NET DAO classes and the same name is used in DynamicLinq.cs (but that appears to be calling http://msdn.microsoft.com/en-us/library/bb503062.aspx which is unrelated to the Take method I'm asking about).

I tried debugging with a breakpoint on this method and it never gets called and as I said before I cannot find it used in the source code.  Maybe it was an idea that never got completed?
Steve Martin, Sep 01, 2012
Reply 1

I too had this same question but was able to figure out what was going on...sort of...

I am actually in the process of implementing this functionality in an application I am working on.

There is a problem though...

If you do not plan to use all of the variables in the SQL statement (such as the below delete command) you will get an error.

Am I missing something?  Didn't anyone test this out?
Below only CustomerID and Version are needed in the SQL.

However, when you use the "Take" functionality you are applying CompanyName, City, and Country to the SQL text event though they are not needed.  This creates an error...

You are actually loading up parameters you are not going to use:

In Oracle, if you attempt to execute this you get:

"ORA-01036: illegal variable name/number"

This means that you are attempting to apply parameters that are not actually in the SQL text.



Do factory folks,

Do you have a solution for this?



Thanks,

Joe



private object[] Take(Customer customer)
         {
             return new object[]  
             {
                 "@CustomerId", customer.CustomerId,
                 "@CompanyName", customer.Company,
                 "@City", customer.City,
                 "@Country", customer.Country,
     "@Version", customer.Version.AsByteArray()
             };
         }

 
public void DeleteCustomer(Customer customer)
        {
            string sql =
            @"DELETE FROM [Customer]
               WHERE CustomerId = @CustomerId 
                AND Version = @Version";

            Db.Update(sql, Take(customer));
        }

 
Adam Rice, Sep 17, 2012
Launch Sql Server Configuration Manager and go to "SQL Server Services" and you should see the Instance ID's under "Name". the name should read "SQL Server(InstanceIDOfYourInstances). Right now I am showing 3. Make sure it is also running. If it's not running right click and start it. Something else, right click the 2008 express version and go to properties and make sure "Built-in Account: " is selected and "Local System" is selected in the dropdown and restart the service. Make sure you restart.
Aug 05, 2011
Reply 2
Hi Steve,

The purpose of the Take() method is to convert the business object into an array with contains the SQL parameter names and values. This is used in combination with Insert and Update queries in the Data Objects project. 
An example on where this is used can be found in the SqlServerCustomerDao class. On line 90 the Db.Insert method is called with on of the parameters the return value of the Take() method. 

The implementation of the Take() method is shown on line 157. Using the Take() method this way reduces repeated code and makes the function easier to read.

Hope this helps.

Regards, Maurits 
Maurits van Beusekom, Sep 02, 2012
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.