Relations without using model generated code

Posts   
 
    
james
User
Posts: 5
Joined: 01-Dec-2005
# Posted on: 02-Dec-2005 22:36:59   

Is there way to get a tables relations and relevant fields for an entity without using model generated code?

For example I can get the foreign keys for an entity by looping through the entitybase.fields and looking for IsForeignKey but I cannot find the related table name for that key (in another thread is was suggested that SourceObjectName would be this, but for me it is the same as the ContainingObjectName)

Secondly can I figure out the like of M:M & M:1 tables that reference this entity? The only place I see this information is in the Model generated code called [Table]Relations but this does not implement and interface or inherit from a base class so I cannot generically instantiate and use it.

Any ideas or suggestions would be appreciated.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Dec-2005 12:59:15   

Why would you want to do it the hard way if you can do it the easy way by simply having the code generated? simple_smile

If you don't want the code being generated, you can try to generate code in a different class which contains the meta-data you want, using the same template statements used to generate the code you want to avoid simple_smile .

Frans Bouma | Lead developer LLBLGen Pro
james
User
Posts: 5
Joined: 01-Dec-2005
# Posted on: 05-Dec-2005 15:23:41   

Hi thanks for the reply Otis. Well the reason is basically I'd creating a generic CRUD interface that uses LLBLGEN as the backbone. The tool will be its own assembly that can be included in any project we have that uses LLBLGEN as its data layer. Basically you just give the tool a tablename and it will create a grid with all the entries pages with context menus to edit/delete etc. with a full edit form etc. So I have done all this but now I'm at the point where I need to show/edit the related entities but that's where I run into troubles. Since this tool is cannot be dependent on a specific project I cannot use any of the generated code and therefore have to only use the base llblgen assemblies.

I wouldn't mind even instantiated the (say for the Northwind.Employees table) the EmployeesRelations class and using reflection go through its properties to pull our related table names+reference fields etc. but the relations class does not inherit from a baseclass so I have no way of generically referencing it.

Would it be possibly to generate a hash or something from the EntityBase that gives relation meta information?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Dec-2005 06:19:21   

I think Frans(Otis) reply solves the whole issue. You may work with templates to generate you the classes you want.