Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Wishlist: Lookup tables -> Enum
 

Pages: 1 2 3
LLBLGen Pro Runtime Framework
Wishlist: Lookup tables -> Enum
Page:1/3 

  Print all messages in this thread  
Poster Message
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 12-Jul-2004 18:39:36.  
Hi. I would like Otis' and the forum's opinion on this feature:

- Have LLBLGen generate code enumerations for designated lookup tables.

Say for example that there is a Countries lookup table with a CountryID PK and CountryName field. This table is practically static for the application and is used as FK in many other tables, so it would be useful to have an enum like this:

enum Country
{
...
Mexico = 56,
Panama = 57,
...
}

The client code would be able to do this:

CustomerEntity c = new CustomerEntity();
c.Name = "ABC";
c.CountryID = Country.Mexico;

instead of hardcoding the ID 56, or querying the DB to retrieve the country by name. The enum produces clean and efficient code.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37236 posts
# Posted on: 12-Jul-2004 19:11:53.  
Ok, and the data for an enum has to be pulled from the db? Or do you also want to add simple lists by hand?

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Trig
User



Location:

Joined on:
09-Jun-2004 14:43:46
Posted:
96 posts
# Posted on: 12-Jul-2004 19:14:17.  
Unfortunately not possible unless the Enum structure would only be changed by doing a refresh of the schema and then rebuilding the LLBL project
  Top
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 12-Jul-2004 19:31:19.  
Otis wrote:
Ok, and the data for an enum has to be pulled from the db? Or do you also want to add simple lists by hand?


Yes, from the DB. In the designer I could specify which are the lookup tables and the ID, Name fields and the template would create a file similar to ConstantEnums.cs, e.g. LookupEnums.cs and add it to the DAL project.

Not sure what you mean 'simple lists by hand'.



  Top
Answer
User



Location:
Phoenix AZ USA
Joined on:
28-Jun-2004 21:13:21
Posted:
363 posts
# Posted on: 12-Jul-2004 20:30:19.  
Quote:
Unfortunately not possible unless the Enum structure would only be changed by doing a refresh of the schema and then rebuilding the LLBL project



I think he is referring to things that dont really ever change, like the states in the US, this would be really handy for that.

Even so, if you added a 51st state, for instance, you could just add another value to the enum with that states ID in the db.

  Top
netclectic
User



Location:
Glasgow, Scotland
Joined on:
28-Jan-2004 11:04:05
Posted:
255 posts
# Posted on: 13-Jul-2004 10:27:21.  
Answer wrote:
Even so, if you added a 51st state, for instance, you could just add another value to the enum with that states ID in the db.

which means you have to distribute a new build if a state is added, i'm sure your clients would love that Wink


Step lightly, Stay free  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37236 posts
# Posted on: 13-Jul-2004 10:34:44.  
obzekt wrote:
Otis wrote:
Ok, and the data for an enum has to be pulled from the db? Or do you also want to add simple lists by hand?


Yes, from the DB. In the designer I could specify which are the lookup tables and the ID, Name fields and the template would create a file similar to ConstantEnums.cs, e.g. LookupEnums.cs and add it to the DAL project.

I'll think about it Regular Smiley

Quote:

Not sure what you mean 'simple lists by hand'.

Adding the name-value pairs by hand in a form Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 13:21:09.  
netclectic wrote:
Answer wrote:
Even so, if you added a 51st state, for instance, you could just add another value to the enum with that states ID in the db.

which means you have to distribute a new build if a state is added, i'm sure your clients would love that Wink



If you are using the application updater block that shouldn't be an issue. Cool


-Skeeter  Top
wayne
User



Location:
Cape Town, South Africa
Joined on:
07-Apr-2004 08:39:37
Posted:
611 posts
# Posted on: 13-Jul-2004 13:35:17.  
I have a Taskperformer that does this or something very simular.

In the config file you specify the tables that you want to be enumerisedRegular Smiley the value field, description field , enum type - char or integer and the file destination. It is very basic but gets the work done.

It only works with SQL Server but you should be able to modify the code very easily for oracle and firebird.

I will try and clean it up and give it to otis to post on the 3rd party section.
Visit http://www.NetReady.co.za - The South African leader in MLM, Network Marketing and Direct selling software.
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 14:15:28.  
wayne wrote:
I have a Taskperformer that does this or something very simular.

In the config file you specify the tables that you want to be enumerisedRegular Smiley the value field, description field , enum type - char or integer and the file destination. It is very basic but gets the work done.

It only works with SQL Server but you should be able to modify the code very easily for oracle and firebird.

I will try and clean it up and give it to otis to post on the 3rd party section.



I use lookup tables in my apps too. However for me, I almost always bind them to comboboxes. So you can bind the ID field to SelectedValue property, and the Text property to the country field. It was just as easy if not easier that way. Can you give an example of another way in which enums might be better? Maybe in the BL Layer?



-Skeeter  Top
wayne
User



Location:
Cape Town, South Africa
Joined on:
07-Apr-2004 08:39:37
Posted:
611 posts
# Posted on: 13-Jul-2004 14:31:36.  
Quote:
I use lookup tables in my apps too. However for me, I almost always bind them to comboboxes. So you can bind the ID field to SelectedValue property, and the Text property to the country field. It was just as easy if not easier that way. Can you give an example of another way in which enums might be better? Maybe in the BL Layer?


This should actually be under architural section...

Binding the tables are not a problem - as that is a good solution to use in interfaces but in BL Code you don't have that luxery and often in your BL you need to know what the value of a certain field represents. What is PaymethodID 1?Confused

Paymethods do not change that often so they are a good example of lookup values that could be enumerized.

For example Paymethods:
1. Credit Card
2. Debit Card
3. Cheque.

I use enums when i have to do a certain something when a payment transaction happens.
Code:
if Ordertransaction.paymentID = Paymethod.creditcard then
else
if Ordertransaction.PaymethodID = Paymethod.Debitcard then
endif
endif


If you did not have enums for PaymethodID then you would have had to hard code the value or you would have had to hard code the description and then lookup the Value part for the matching description.

I found it usefull to have enums for lookup table values that do not change that often - especially system settings like employee maritial status, titles, security groups ext.. but the choice of which lookuptables to enumerize must be made carefully. Seeing that you don't want to release a new version just because you added a new Bank Branch.Shocked
Visit http://www.NetReady.co.za - The South African leader in MLM, Network Marketing and Direct selling software.
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 14:53:18.  
wayne wrote:
Quote:
I use lookup tables in my apps too. However for me, I almost always bind them to comboboxes. So you can bind the ID field to SelectedValue property, and the Text property to the country field. It was just as easy if not easier that way. Can you give an example of another way in which enums might be better? Maybe in the BL Layer?


This should actually be under architural section...

Binding the tables are not a problem - as that is a good solution to use in interfaces but in BL Code you don't have that luxery and often in your BL you need to know what the value of a certain field represents. What is PaymethodID 1?Confused

Paymethods do not change that often so they are a good example of lookup values that could be enumerized.

For example Paymethods:
1. Credit Card
2. Debit Card
3. Cheque.

I use enums when i have to do a certain something when a payment transaction happens.
Code:
if Ordertransaction.paymentID = Paymethod.creditcard then
else
if Ordertransaction.PaymethodID = Paymethod.Debitcard then
endif
endif


If you did not have enums for PaymethodID then you would have had to hard code the value or you would have had to hard code the description and then lookup the Value part for the matching description.

I found it usefull to have enums for lookup table values that do not change that often - especially system settings like employee maritial status, titles, security groups ext.. but the choice of which lookuptables to enumerize must be made carefully. Seeing that you don't want to release a new version just because you added a new Bank Branch.Shocked


Thats what I was thinking for comparing values in the BL. I guess enums could be pretty nice for that. Regular Smiley

I am using adapter. In my BL I have an EmployeeManager class, with a GetEmployee method that returns an employee entity. In my PL I required checking the employees role, which has a FK to the Role table. In my PL I didn't want to do
Code:
if(employee.Role = 1)

Sooo I wrote in my BL to fill the Role Entity as well. So now GetEmployee returns the employee, with the relation to Roles filled. So now I have something like this
Code:
if(employee.Role.Description == "administrator")


Using enums in this case would be nice if your forgot the different roles an employee could have. Plus autocomplete is nice Laugh Also, not having to do the extra coding in the EmployeeManager class could have been avoided, as writing the extra code to fill a Role Entity in the EmployeeManager class gets confusing/messy as your relations get deeper and more complex.


-Skeeter  Top
wayne
User



Location:
Cape Town, South Africa
Joined on:
07-Apr-2004 08:39:37
Posted:
611 posts
# Posted on: 13-Jul-2004 15:00:32.  
Yah - it would be much nicer to rather use enums in the security profile role than string comparingRegular Smiley

If you want the Taskperformer that generaters a enum file for you...
You can get it from here until Otis has had time to upload it to the 3rd party section.

Code:
ftp://196.36.190.121/LLBLGEN/TaskPerformers/EnumTaskPerformer.rar
Username : llblgenguest
Password : treeboat
Visit http://www.NetReady.co.za - The South African leader in MLM, Network Marketing and Direct selling software.
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 15:03:00.  
wayne wrote:
Yah - it would be much nicer to rather use enums in the security profile role than string comparingRegular Smiley

If you want the Taskperformer that generaters a enum file for you...
You can get it from here until Otis has had time to upload it to the 3rd party section.

Code:
ftp://196.36.190.121/LLBLGEN/TaskPerformers/EnumTaskPerformer.rar
Username : llblgenguest
Password : treeboat


Thanks Wayne, You the man.


-Skeeter  Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 16:29:57.  
Just curious

Your code generated this:
Code:

public enum RoleType : int
    {
        Administrator = 1,
        User,
        Guest
    }


I use it and still have to cast to int like this
Code:

if(_employee.FK_RoleId == (int)RoleType.Administrator)



The base type was set to int. So why do you still have to cast? Even on the MSDN examples they have it cast after the base type was declared. Does anyone know why? If so, what is the point of declaring the base type?

MSDN's Example:
Code:

public class EnumTest
{
enum Range :long {Max = 2147483648L, Min = 255L};
public static void Main()
{
long x = (long) Range.Max;
long y = (long) Range.Min;
Console.WriteLine("Max = {0}", x);
Console.WriteLine("Min = {0}", y);
}
}
-Skeeter  Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 16:32:59.  
Nevermind, MSDN explained it:

Quote:
The underlying type specifies how much storage is allocated for each enumerator. However, an explicit cast is needed to convert from enum type to an integral type. For example, the following statement assigns the enumerator Sun to a variable of the type int using a cast to convert from enum to int:

int x = (int) Days.Sun;



Wayne, have you tested char for enum type? MSDN says this:
Quote:

base-type (Optional)
The underlying type that specifies the storage allocated for each enumerator. It can be one of the integral types except char. The default is int.


In your documentation you have:
Quote:
3. EnumType_X is the type of enumerator int or char.


-Skeeter  Top
wayne
User



Location:
Cape Town, South Africa
Joined on:
07-Apr-2004 08:39:37
Posted:
611 posts
# Posted on: 13-Jul-2004 16:43:37.  
No - i havn't used the char type - sorry i thought it was possible to use char...seeing that you could use char in other languages becuase its base is of type byte - well it use to be...havn't checked what it is in dot net.

The type can actually be anything - as you specify it.

PS - I added http support - http://196.36.190.121/LLBLGEN/
Visit http://www.NetReady.co.za - The South African leader in MLM, Network Marketing and Direct selling software.
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 16:50:46.  
wayne wrote:
No - i havn't used the char type - is something wrong with it?

The type can actually be anything - as you specify it.

PS - I added http support - http://196.36.190.121/LLBLGEN/



MSDN says you can't use a char type, only integral.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemenumclasstopic.asp

Read under remarks.



-Skeeter  Top
wayne
User



Location:
Cape Town, South Africa
Joined on:
07-Apr-2004 08:39:37
Posted:
611 posts
# Posted on: 13-Jul-2004 16:54:49.  
sorry i thought it was possible to use char...seeing that you could use char in other languages becuase its base is of type byte - well it use to be...havn't checked what it is in dot net.
Visit http://www.NetReady.co.za - The South African leader in MLM, Network Marketing and Direct selling software.
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 16:58:32.  
wayne wrote:
sorry i thought it was possible to use char...seeing that you could use char in other languages becuase its base is of type byte - well it use to be...havn't checked what it is in dot net.



Its not a problem. I wasn't trying to use it. I just wanted to let you know so when Otis puts it in third party downloads he doesn't get people bitching a fit about it Cool


-Skeeter  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37236 posts
# Posted on: 13-Jul-2004 17:17:03.  
Bitching about 3rd party stuff is flushed through to the original authors. Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 13-Jul-2004 18:31:08.  
Wayne, thanks for the performer! I'm testing it now but get exceptions ("SQL Server does not exist or access denied") so it seems that there is a problem with the connection string. I have no problem refreshing the catalog and generating the regular code though using the built-in templates. Any ideas?



  Top
wayne
User



Location:
Cape Town, South Africa
Joined on:
07-Apr-2004 08:39:37
Posted:
611 posts
# Posted on: 13-Jul-2004 19:25:36.  
You should open your LLBLGen project. The select the generate - select the task performer then generate. The connection string is retreived from the project - i have no control over that.

hmm...maybe Otis is no longer storing the username and password...I know he was talking about security issues...The task performer works with the 28th June release. If that is the case - i will release a patched version. Please give me some feedback.
Visit http://www.NetReady.co.za - The South African leader in MLM, Network Marketing and Direct selling software.
 
Top
Skeeterbug
User



Location:
Phoenix, AZ
Joined on:
21-May-2004 19:18:48
Posted:
165 posts
# Posted on: 13-Jul-2004 19:31:06.  
wayne wrote:
You should open your LLBLGen project. The select the generate - select the task performer then generate. The connection string is retreived from the project - i have no control over that.

hmm...maybe Otis is no longer storing the username and password...I know he was talking about security issues...The task performer works with the 28th June release. If that is the case - i will release a patched version. Please give me some feedback.


Mine worked but I was using the June version. I just upgraded and havn't checked.


-Skeeter  Top
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 13-Jul-2004 19:38:02.  
wayne wrote:
hmm...maybe Otis is no longer storing the username and password...I know he was talking about security issues...The task performer works with the 28th June release. If that is the case - i will release a patched version. Please give me some feedback.


That must be it, because I'm using July/12. Thanks!

Btw, is there a way for the generated enum.cs file to be added to the DatabaseGeneric project?
  Top
Pages: 1 2 3  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.