Oracle Check constraints

Posts   
 
    
Posts: 67
Joined: 10-Jun-2009
# Posted on: 12-May-2011 12:19:11   

I'm using LLBLGen Pro 3.1 Final on an Oracle database. Our database administrators are using Oracle Designer to maintain the database, in which they define possible values for a specific column. For instance, we have a relation table, which holds name and contact info. One column in this table is type, which has two possible values: - C = "Customer" - S = "Supplier"

this is implemented as a check constraint in Oracle: CONSTRAINT "customer_type" CHECK (TYPE IN ('C', 'S')) ENABLE

Is it possible to create a template in LLBLGen which generates a switch statement based on the possible values of the column? I want to add a property to the Entity which translates the possible values:


public String TypeTranslated
{
    get
    {
        switch (Type)
        {
            case "C":
                return "Customer";
            case "S":
                return "Supplier";
        }
    }
}

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 12-May-2011 15:47:18   

You should be able to a use a Type Convertor http://www.llblgen.com/documentation/2.6/Concepts/concepts_typeconverters.htm to do this for you.

Matt

Posts: 67
Joined: 10-Jun-2009
# Posted on: 12-May-2011 16:26:54   

I already have a type converter in place to convert the column in the database to the proper enum type.

Hoever, I want to have another (readonly) property, which translates the type to a humanly readable format.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 12-May-2011 17:32:13   

Sorry, my misunderstanding.

Have a look at http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_addingusercode.htm

The two usual methods are the user code sections in the generated code, or to use partial classes.

Matt

Posts: 67
Joined: 10-Jun-2009
# Posted on: 13-May-2011 08:20:50   

This was just an example. We are using LLBLGen for numerous projects, in which I want this construction for every column which had a check constraint defined. I know I could set this code in a partial class or user region code, but I want this to be generated by LLBLGen.

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 13-May-2011 10:10:37   

For each and every different column, you will have to type in somewhere the readable meaning of the values used in this column (check constraint). eg. C = Customer.

So manual intervention is needed anyway.

Posts: 67
Joined: 10-Jun-2009
# Posted on: 13-May-2011 10:25:16   

Actually, the text returned isn't coded in the switch itself, but in a call to a function which finds the text in a resource file maintained by a third party... So if I could find a way to add some code through the template, there isn't any manual labor left for me :-)

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 13-May-2011 10:49:54   

2 questions:

1- If you add code throught temoplates, how would you pick which fields to have this code generated for and which are not?

2- What if you have 'C' in some column which means "Customer", and in another column it means something else, say "'City".

How would you deal with these in one resource file?

Because of all these issues I always try to avoid codes in the database.