views:

47

answers:

0

Hi I have a database with a "configs" table each new row in the configs table is 4 a different client which can config his environment to his liking (theme,companyname,language, culture...)
one record,lets say id=-1, is the default config. all new configs should copy everything from there
i want that each time i (the main admin) add a new record to this "configs" table, all related records of config -1 should b also inserted to their respective table with the configid of the brand new row

so i have code that overrides the submitchanges of the datacontext.
heres my code meanwhile

MyBase.SubmitChanges(failureMode)
Dim DefConfig = From cx In DBContext.Configs Where cx.ConfigID= -1    
                    For Each p In (New Config).GetType.GetProperties
                        If p.PropertyType.BaseType.Name <> "ValueType" And p.PropertyType IsNot "".GetType Then
                            'add subrecords!
                            Dim subrecs = p.Attributes
                        End If
                        SubmitChanges()
                    Next

but for the life of me i dont know how to continue. there can b 30+ tables where there may be such subrecords
somehow, i want to tell linq, grab all subrecords of "ExpenseTypes" or "Projects" etc etc, copy 'em, change the configid from -1 to whatever the new id is and add 'em to the db.
is this at all possible? in worstcase, i believe i could construct sql statements for each table, using its name etc. but it would be a shame, as i do have insert logic for specific tables in my partial classes
thank you vey much