Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Copy Records With Table Hierarchy
 

Pages: 1
LLBLGen Pro Runtime Framework
Copy Records With Table Hierarchy
Page:1/1 

  Print all messages in this thread  
Poster Message
Dan1
User



Location:

Joined on:
20-Sep-2007 16:09:06
Posted:
41 posts
# Posted on: 25-Apr-2008 16:10:53.  
Is there any way with LLBLGen Pro generated code (SS,2.5) to copy records and the child path to a new set of records?

Currently I do this in a stored procedure using complex joins. Take a structure like this as follows:

tblParent (uses identity primary key column)
-->tblChildren (uses identity primary key column)
     -->tblChildrensChildren (uses identity primary key column)

The only real complex part of this scenario is that when you copy the record in tblParent to a new record you must copy all of the children but keep the foreign key of the new parent and disregard the old foreign key, and then you must do the same thing for all of the ChildrensChildren. It's involved me having to write stored procedures with fairly complex joins and FETCH statements. New primary keys are generated for new (copied) records so after a record is inserted, the new primary key must be retrieved and is used as te foreign key in the child table.



I'm not asking if I can use the stored procedure in LLBGen Pro because I know I can, I am wondering if I could disregard the stored procedure and do this failr simple with LLBLGen Pro? Is there something in the object model I am missing that could simplify this or are we would I have to do a similar thing with LLBLGen Pro that I am with the stored procedures but just with using .NET code (Loops, entity loads, updates, etc).

  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8138 posts
# Posted on: 26-Apr-2008 04:39:18.  
Could you please indicate what are you trying to achieve?

(Given a Stored Procedure, fetch the results and fill entity objects hierarchically??)


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Dan1
User



Location:

Joined on:
20-Sep-2007 16:09:06
Posted:
41 posts
# Posted on: 26-Apr-2008 05:31:53.  
The app allows the user to copy the current record (and all child records in child tables) to a new set of records to use as a template for a new project while keeping the old records in tact and the new records are exact duplicates of the ones they were copied from except all of the primary keys and foreign keys would be different.

How do you recommend I do this with LLBLGen Pro? Currently I am using SQL Server Stored Procedures, but I am wondering if LLBLGen Pro would be simpler or if there was something built into the object model that would facilitate this.
  Top
WayneBrantley
User



Location:
USA
Joined on:
10-Mar-2006 16:20:08
Posted:
1118 posts
# Posted on: 26-Apr-2008 05:35:46.  
If you already have this working in a stored proc, why would you want to change that?

Plus, to do it in LLBLGen entities, you would have to fetch all the data, only to send it all back for saving. Stored procedure would be much more efficent.

However, if you _insisted_ in doing it in LLBLGen, I guess you could:

- loop through all entities and mark all fields a being modified and mark all entities as new.
- save recursively

Again, highly recommend leaving well enough alone and keeping the stored proc running! Regular Smiley


SelfServicing, .Net 4.5, Web Applications, SqlServer 2014  Top
Dan1
User



Location:

Joined on:
20-Sep-2007 16:09:06
Posted:
41 posts
# Posted on: 26-Apr-2008 05:46:45.  
If that's the only way (as expected) then I am fine keeping it as is. I've just added a couple of tables to the application that I haven't written the copy routines for yet so I figured now is the time to re-evaluate it. Advantage of .NET code is simpler to debug (Grrr.. if we had moved our DB to SQL Server 2005 by now we could even investigate a .NET Code Procedure on the server Wink )

Unless anyone else has any different insight on this I'll consider this the end of the thought for me to use LLBLGen Pro for this task.
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8138 posts
# Posted on: 26-Apr-2008 06:37:42.  
Please try this: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7568

David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
WayneBrantley
User



Location:
USA
Joined on:
10-Mar-2006 16:20:08
Posted:
1118 posts
# Posted on: 26-Apr-2008 13:44:17.  
Good link - that would be how you would implement what I suggested. Although wouldn't it be a problem to have the pkey already set? Might need to empty that (since it is identity) - dunno LLBLGen pro layer might ignore it on IsNew anyway...
SelfServicing, .Net 4.5, Web Applications, SqlServer 2014  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8138 posts
# Posted on: 27-Apr-2008 20:45:33.  
If the PK is autoincrement or has a sequential routine the PK-reset is no needed, though if it isn't, the PK should be reseted as you pointed.

David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.