Jump to content


Update Method nDepth=1 Example


  • Please log in to reply
4 replies to this topic

#1 Guest_kittisoongswang_*

Guest_kittisoongswang_*
  • Guests

Posted 04 October 2005 - 09:11 AM

I try to learn to use more than 1 level of nDepth. I use northwind example that have only 2 table customers and orders.

I can use Insert method by create customers object and provide provide properties and create related collection object. After that I create 2 orders object and add to collection. Finally I call Insert Method and passing customer object and 1. The data go into database.

But for update and delete, I tried but do not work.

Pleaes give me an example code.

Thank :(

#2 Guest_Paul_*

Guest_Paul_*
  • Guests

Posted 04 October 2005 - 10:39 AM

The code for Updating child objects is exactly the same as you did for the Insert. In the following example, I am updating few orders related to a customer and then calling update method with depth as 1 so that the updated objects can be persist.

Customers objInfo = new Customers();
CustomersFactory objFactory = new CustomersFactory();
Orders objOrder;

objInfo.CustomerID = "ALFKI";

objFactory.Load(objInfo, 1);

objOrder = objInfo.Orders[0];
objOrder.ShipAddress = "new Address";

objOrder = objInfo.Orders[1];
objOrder.ShipAddress = "new Address";
  	
objFactory.Update(objInfo, 1);


#3 Guest_kittisoongswang_*

Guest_kittisoongswang_*
  • Guests

Posted 12 October 2005 - 07:39 AM

Thank you for your suggestion.

I tried by using your sample code. First it not work, so I debug it and found that I need to revise generated code in order to make it work. So I think you should check it out. If it a bug (I not sure), please try to fix it.

The following is part of generated code for CustomersFactory class. (I use Customers and Orders of Nortwind).

Public Function Update(ByVal objInfo As Customers, ByVal nDepth As Int32) _
Implements ICustomersFactory.Update
Try
' skip some code

If (nDepth <> 0) Then
Dim _ReCustomerOrdersFactory As OrdersFactory = _
New OrdersFactory(getConnection())

_ReCustomerOrdersFactory.Save(objInfo.ReCustomerOrders, nDepth)

End If
' skip some code

End Function

It not work if I use the following code. (I did assigned value for orders)
objFactory.Update(objInfo, 1)

I debug and revised code of update method as following in bold to make it work.
Public Function Update(ByVal objInfo As Customers, ByVal nDepth As Int32) _
Implements ICustomersFactory.Update
Try
' skip some code

If (nDepth <> 0) Then
Dim _ReCustomerOrdersFactory As OrdersFactory = _
New OrdersFactory(getConnection())
nDepth = nDepth - 1
_ReCustomerOrdersFactory.Save(objInfo.ReCustomerOrders, nDepth)

End If
' skip some code

End Function

So please take a look at this issue and if it a software bug, please fix it. If it not a bug, please forgive me.

#4 Guest_Paul_*

Guest_Paul_*
  • Guests

Posted 12 October 2005 - 01:33 PM

I feel its a bug in the VB template where nDepth-1 is missing in calling the Save method. The C# template is OK and you can fix this issue by doing the following change in the VB template.

Please open the vb template in template IDE and modify the following lines with -1.

1. You can find the VB Factory ComponentFactory_vb.ts template at
%Installation Directory%\TierDeveloper .Net 5.0\Patterns\PrePackaged\VBComponent\Source\Components

2. go to line number 950 and replace
_<%=rel.Name%>Factory.save<%=CurrentObject.Name%><%=rel.Name%>(objInfo.<%=rel.Name%>, nDepth, bCacheEnable, objInfo)

with

_<%=rel.Name%>Factory.save<%=CurrentObject.Name%><%=rel.Name%>(objInfo.<%=rel.Name%>, nDepth-1, bCacheEnable, objInfo)

3. go to line number 952 and replace

_<%=rel.Name%>Factory.Save(objInfo.<%=rel.Name%>, nDepth<%=szCacheParam%>)

with

_<%=rel.Name%>Factory.Save(objInfo.<%=rel.Name%>, nDepth-1<%=szCacheParam%>)

Save the template and generate the code again, i hope it will work.

#5 Guest_kittisoongswang_*

Guest_kittisoongswang_*
  • Guests

Posted 12 October 2005 - 05:45 PM

Thank you very much. I will tried it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users