Backup database model to file/blob

Posts   
 
    
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 10-Feb-2009 11:28:23   

I'm on 2.0.0.0 final, VS2005 VB, SQL Server 2005, SelfService.

We need to be able to backup an entire hierarchy of records so that the user can restore if the screw up. So say we have Orders and OrderLines; we need to backup an order and all its lines in such a way that we can restore them.

Is XML the way?

Regards

Steve Mann

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 10-Feb-2009 11:40:24   

A binary memory stream is the best option. I was just reading a user's meesage about the same thing here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15206&StartAtMessage=0&#84968

Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 10-Feb-2009 13:11:18   

Thanks for the quick response.

I tend to use LLBLLGen (or 'Billy' as we call it) in a very simple way -- get a Collection, give it to a Janus grid, etc. I don't really understand 'directed graphs' and so on.

Whether I use XML or not, I must ensure that all children and grandchildren are exported. If I just get the top level entity I don't seem to get all children. So I tried the code below.

Is this because of lazy loading? When I loop through (some of) the children I get (all) the children. In other words, there are ent4, ent5... which I don't refer to but they still get fetched.

Note I don't do anything in the inner loop!

 Dim MasterBackup As New DemMasterSchedulingProjectsEntity(GLB_MasterProjectEntity.MasterSchedulingProjectId)
                MasterBackup.GetMultiDemSchedulingProjects(True)

                For Each ent As DemSchedulingProjectsEntity In MasterBackup.DemSchedulingProjects
                    For Each ent2 As DemDemandPeriodsEntity In ent.DemDemandPeriods
                        For Each ent3 As DemDemandPeriodPresencesEntity In ent2.DemDemandPeriodPresences

                        Next
                    Next
                Next

                Dim writer As New IO.StreamWriter("c:\test.XML")
                Dim MasterBackupXml As String = String.Empty
                MasterBackup.WriteXml(MasterBackupXml)
                writer.Write(MasterBackupXml)
                writer.Close()
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 10-Feb-2009 21:05:15   

I am surprised that your code loads ent4 and ent 5s - if you step through the code can you watch the queries in SQL profiler to see what gets loaded when...?

IMO, Adapter would be a better solution in this scenario. You then have complete control of what gets loaded into the entity graph, and when, through the use of PreFetch paths - no lazy loading is used.

Although it does have technical definition, "graph" tends to get used on here to mean an in-memory structure of related entites. We tend to avoid the use of "hierarchy" as that usually points toward entities which inherit from one another.

Matt