Get the primary tables for a given table

Is there a feature you'd like us to add? Post it here.

Get the primary tables for a given table

Postby albertobr on Tue Mar 09, 2004 3:53 pm

Hi, congratulations and thanks for this well done job.
My question, Is there a way to know what columns of a given table are primary keys in other table that plays a parent role with this one?. I´m trying to create an object hierarchy that mimics my relational database, but I dont find how to link a child with its parents.
And for the same price another question, have you an example of interface code in c# templates or interface is only targeted for vbscript templates?
Thanks in advance
Alberto
albertobr
 

Postby mike.griffin on Tue Mar 09, 2004 4:56 pm

Both Justin and myself have written systems that hookup, via code generation, an entire object model hierarchically. I have pointed your question out to Justin who is more familiar with this technique. There is the ForeignKeys collection. I can give you a query, that you can execute through IDatabase.ExecuteSql that will help you if need be, it returns an ADO recordset that you can loop through. However, ITables has a foreign key collection, I think this is what you need.

Code: Select all
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name = 'Employees'

Look at our ForeignKeys collection on the Meta Data Browser window, that's your best bet, you can look at the INFORMATION_SCHEMA views in your master table if your using SQL to see if that helps. Line 44 of \"SQL_DataInserts.jgen\" calls ExecuteSql().

The C# templates are in the C# directory under Templates
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby mike.griffin on Tue Mar 09, 2004 5:21 pm

Code: Select all
public class Employee
{
   // In C# you can have type and formal name the same
   public virtual Dependents Dependents
   {
      get
      {
         // Load on demand only
         if(dependents == null)
         {
            dependents = new Dependents();
            dependents.Where.EmployeeID.Value = this.EmployeeID;
            dependents.Query.Load();
            this.SubObjectCollection.Add(dependents);
         }

         return dependents;
      }
   }
   
   private Dependents dependents = null;
}


Thus

Employees emps = new Employees();
int count = emps.Dependents.Count;

Then, you customize Save() so that it saves anything in your SubObjectCollection as well as yourself. Also, open your User Meta Data window, and give your ForeignKeys nice names if you need to use them in your script.

There's more to it than that, of course, but that will get you thinking. And at some point, I'm sure we'll release the templates to do so.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Hierarchical Architectures

Postby justin.greenwood on Tue Mar 09, 2004 6:27 pm

We are implementing a second FKey collections, possibly called \"IndirectForeignKeys\" that contain and backwards references to the selected table. You should see it in the next build.

As far as templates are concerned, I've created templates that generate hierarchical object model classes for my real job (I can't post those unfortunately). I plan to build a separate architecture with the same philosophy for the public someday. Until then, I will try and get an example posted so you can hookup your child objects/collections with your existing architecture.
User avatar
justin.greenwood
Site Admin
 
Posts: 441
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby on Wed Mar 10, 2004 5:27 pm

Thanks for your advice, I'll wait for the IndirectForeignKeys enhancement.
 

Postby mike.griffin on Sat Mar 13, 2004 2:23 am

If you're using SQL Server then build mygen0910b.exe has what you're looking for. We'll get ACCESS up-to-date real soon, possibly this weekend.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN


Return to Enhancements

Who is online

Users browsing this forum: No registered users and 1 guest

cron