Generate classes from using data

Posts   
 
    
bjtomli
User
Posts: 12
Joined: 17-Feb-2012
# Posted on: 24-Apr-2012 18:51:26   

I did a few searches and couldn't find any info on generating classes using actual data from the DB. Is it possible to create templates, tasks, etc. that will load data and generate files from the data using LLBLGen Pro's designer?

I'm using version 3.5.

Walaa avatar
Walaa
Support Team
Posts: 14954
Joined: 21-Aug-2005
# Posted on: 24-Apr-2012 18:59:27   

Could you give an example of what are you trying to do? Example of data ready and the output generated.

bjtomli
User
Posts: 12
Joined: 17-Feb-2012
# Posted on: 24-Apr-2012 19:31:05   

Right now I have a table called CodeSet and one called CodeValue. Many CodeValues to a CodeSet. Based on the data entered in the the two tables I want to generate CodeSet classes for each row of data in in the CodeSet table and a class for each row of data in the CodeValue table. I currently have a custom built Code Generation console app for doing this. It's a home brew solution with my own templates. I actually use LLBLGen's entities for loading the data and doing this in my custom solution but as I learn more about creating LLBLGen templates I thought it would be nice to include it as a task in my LLBLGen project so all my code generation was self contained in one area (a LLBLGen project).

There are currently a number of classes involved in this solution so I can't include everything here but I pasted a simple example of what gets generated based on values in the two tables. This example is a CodeSet (Status) and two CodeValue's (Active & InActive) that have FK relations back to the Status CodeSet. My app generates the class Status with properties for each CodeValue that are of type StatusCodeValue, also generate by the tool.


    public class StatusCodeValue : CodeValue
    {
        public StatusCodeValue(CodeValueEntity codeValueEntity) : base(codeValueEntity){}
    }

    public class Status : CodeSetUIBase //CodeSet entry
    {
         public Status() : base("Status") { }
        public StatusCodeValue Active
        {
             get { return (StatusCodeValue) CodeSetManager.GetCodeValue(this.CodeSetName, "ACTIVE"); }
        }
        public StatusCodeValue InActive
        {
             get { return (StatusCodeValue) CodeSetManager.GetCodeValue(this.CodeSetName, "INACTIVE"); }
        }
    }

It's my way of creating a list of Enum in a table but being able to code using the values using strongly type objects. Of course, there are a few other fields in the table that allow for more flexibility than a enum. Many of my tables in the schema have FK's to CodeValues.

Walaa avatar
Walaa
Support Team
Posts: 14954
Joined: 21-Aug-2005
# Posted on: 24-Apr-2012 21:00:48   

Code is generated according to the schema.

If you want to generate code according the data, then these shouldn't be considered as data. But rather metadata, as data should be subject to updates, and this should not affect the model or the schema.

bjtomli
User
Posts: 12
Joined: 17-Feb-2012
# Posted on: 24-Apr-2012 22:52:34   

Yes, It's data but it's referencial seed data that will not change once created for a given version of the software. Given that LLBLGen is a strong code generation tool I thought it might be able to handle templates that use schema information as well as data in a schema to generate its output.

If it can't, no big deal. We'll continue to use our current solution for generating classes based on data. I did feel it was worth the time to investigate as encapsulating all code generation in one LLBLGen project file would eliminate the extra step of executing our custom code generation tool.

Thanks for the quick response.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Apr-2012 07:30:18   

As a matter of fact, you can. Some time ago this was a wanted feature (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=1114)

That ended in a third-party task performer. You can download it at LLBLGen Site -> Customer area -> v2.0 Downloads -> Third party -> Enum generator task performer:

Enum generation from DB Tables

Author: Wayne Barker & Pandelis Goros Database Support: SQL Server Language: C#

Included in this archive: The Source - source code Taskperformer DLL - Gen_Enums.dll Task file - Comm.tasks.GenerateEnums.tasks

Description: This Taskperformer allows the user to generate a enum code file that is based on the contents of lookup tables in the database. The Taskperformer has been tested with the 6th December release of LLBLGen (ver 2.0.0.0). - Source Code included.

DISCLAIMER: This taskperformer is supplied as is, without any warranty or support. Use it at your own risk. It is always wise to first check the sourcecode, and before using it, make a backup copy of your project.

Read the enclosed readme for details about how to setup the taskperformer for your project.

The assembly and source code are provided. I'm not sure but I think you will need to modify it a little bit to make it work on v3.5. To get an idea you can start at SDK - Implementing a task performer.

David Elizondo | LLBLGen Support Team