I need to enhance some templates I'm working on to support checking for "owned" rows. A good example is if you have a contact row with a one to many relationship with an address row. If you are referential integrity you cannot do a delete of contact if there are still address rows. Now you could arbitrarily always delete all the address rows first then delete the contact, but what I want to do is automatically check for existance of address rows and warn the user that dependancies exist.
By hand this isn't complex, but I'd really like it baked into the template. So what I'd want to do is this:
a) Generate a check in the UI code for dependent rows, with the associated error message code, resources, etc, just like we can already do for something like a date check.
b) Generate deletes of dependant rows in the stored procedures, or generate calls in the DAL to do the same.
c) Possibly step towards master / detail generation
Now currently I'm dealing with some relational issues by adding extra comments in the schema itself, but the foriegn keys are there but point in the wrong direction (as least for my purposes). In my example the contact table doesn't have foriegn keys to address (or at least that I know how to find in schemaexplorer), but there are keys to contact from address.
My assumption at this point is it's possible, but I just don't know codesmith's schemaexplorer well enough to do it.
Hello,
Please take a look at the Csla source code in the templates folder. There is a project called Schema Helper, this should be what you are looking for. It will detect all the different kinds of relationships. If it won't do the parent to child then you may need to add a little bit of logic to it. I find that debugging and stepping into the logic is a real time saver when making modifications.Thanks-Blake Niemyjski
Blake Niemyjski CodeSmith Tools, LLC. Software Development Engineer Blog: http://windowscoding.com/blogs/blake/ .NetTiers team | Visit http://www.nettiers.com
What exactly is your question about SchemaExplorer? If I were doing this, I would create unit tests first and then use a compiled lib. Your going to have to make calls via C# to the database to get the data or use GetTableData()...Thanks-Blake Niemyjski
Sorry if I wasn't clear. What I know how to do in SchemaExplorer is to determine the foreign keys associated with a table. What I see when looking at the SchemaExplorer info shows me the "parents" when I'm looking at the foreign key information on the "children". There are many examples of that in storedprocedures.cst, DBDocumentor, etc.
What I want to do is the opposite. When looking at the parent I'd like to walk through a list of the children. So if I have a contact table with parent rows, and those parent rows can own rows in an address table, and email table, etc, I'd like to be able to generate code that knows of those relationships. Today I can do that when I referencing the address (child) table, but I'd like to see the relationships when refering to the contact (parent) table.