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
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?
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 you have a solution for this?
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
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.
Maurits van Beusekom, Sep 02, 2012