Entity by Unique Keys

Posts   
 
    
kulki
User
Posts: 26
Joined: 20-Dec-2004
# Posted on: 20-Dec-2004 16:26:34   

Hi, In the generated code it creates constructors based on the Primary Key. For instance I have a User table with primary key SysId then I LLBLGen creates a constructor User(int sysId) which is perfectly fine. However I also have a unique key on userId and therefore I would like to create a constructor of the form User(string userId). Do I need to create this constructor myself or it already created by the generated code. thanks

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 20-Dec-2004 17:07:48   

kulki wrote:

Hi, In the generated code it creates constructors based on the Primary Key. For instance I have a User table with primary key SysId then I LLBLGen creates a constructor User(int sysId) which is perfectly fine. However I also have a unique key on userId and therefore I would like to create a constructor of the form User(string userId). Do I need to create this constructor myself or it already created by the generated code. thanks

Unfortunately I don't think there's a quick way to do this out of the box (meaning: single line)... In the Manager Classes (http://llblgen.com/tinyforum/Messages.aspx?ThreadID=1892) I implemented some FetchUsingUniqueConstraint methods. These might be of interest to you (adapter only)...

Otherwise:

entity.UserId= userId;
adapter.FetchEntityUsingUniqueConstraint(entity, entity.ConstructFilterForUCUserId())

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-Dec-2004 17:38:52   

kulki wrote:

Hi, In the generated code it creates constructors based on the Primary Key. For instance I have a User table with primary key SysId then I LLBLGen creates a constructor User(int sysId) which is perfectly fine. However I also have a unique key on userId and therefore I would like to create a constructor of the form User(string userId). Do I need to create this constructor myself or it already created by the generated code. thanks

The constructor can't be done, say you have a PK of type string and a unique constraint on a field of type string.

2 times the same constructor, which will not compile. Same goes for 2 UC's which are both a string for example, also won't compile.

Therefore the entities have FetchUsingUC<uniqueconstraintfields>(field1, ...) methods, one per UC.

Frans Bouma | Lead developer LLBLGen Pro
kulki
User
Posts: 26
Joined: 20-Dec-2004
# Posted on: 20-Dec-2004 23:29:22   

Otis wrote:

kulki wrote:

Hi, In the generated code it creates constructors based on the Primary Key. For instance I have a User table with primary key SysId then I LLBLGen creates a constructor User(int sysId) which is perfectly fine. However I also have a unique key on userId and therefore I would like to create a constructor of the form User(string userId). Do I need to create this constructor myself or it already created by the generated code. thanks

The constructor can't be done, say you have a PK of type string and a unique constraint on a field of type string.

2 times the same constructor, which will not compile. Same goes for 2 UC's which are both a string for example, also won't compile.

Therefore the entities have FetchUsingUC<uniqueconstraintfields>(field1, ...) methods, one per UC.

Well Say that a UI programmer wants to create a new instance of the User object based on the UserId. Are you saying that I need to code something like this:

User myUser = User.FetchUsingUC("Thomas");

As a UI programmer I would expect the programmer not to know anything about the Unique Constraints.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Dec-2004 10:10:39   

kulki wrote:

Otis wrote:

kulki wrote:

Hi, In the generated code it creates constructors based on the Primary Key. For instance I have a User table with primary key SysId then I LLBLGen creates a constructor User(int sysId) which is perfectly fine. However I also have a unique key on userId and therefore I would like to create a constructor of the form User(string userId). Do I need to create this constructor myself or it already created by the generated code. thanks

The constructor can't be done, say you have a PK of type string and a unique constraint on a field of type string.

2 times the same constructor, which will not compile. Same goes for 2 UC's which are both a string for example, also won't compile.

Therefore the entities have FetchUsingUC<uniqueconstraintfields>(field1, ...) methods, one per UC.

Well Say that a UI programmer wants to create a new instance of the User object based on the UserId. Are you saying that I need to code something like this:

User myUser = User.FetchUsingUC("Thomas");

UserEntity myUser = new UserEntity(); myUser.FetchUsingUCUserID("Bla");

there is no other way to make it work otherwise, as a constructor like: public UserEntity(string id) {...} is the same as public UserEntity(string name) {...}

As a UI programmer I would expect the programmer not to know anything about the Unique Constraints.

If the developer doesn't know what the uniquely identifying PK field(s) are for a given entity he can never fetch an entity whatsoever, unless using a collection fetch and grab the first one. Some information is ESSENTIAL for developing software. Not allowing developers to have that information is limiting developers writing good software.

Frans Bouma | Lead developer LLBLGen Pro