Can LLBLGen fix my poor data model design?

Posts   
 
    
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 20-Apr-2005 16:33:35   

Five years ago I was the recipient of an existing data model. It was designed with best intentions, but we've all learned a thing or two since then, and I've discovered there is a poor relationship between two of my tables.

I deal with students, so students are registered into classes and then there is attendance taken for those registrations. However, due to some issues I won't get into, the relationship between Registration and Attendance is non-existant.

So, I have a stu_id and cls_id column in both tables, but they can not be foreign keyed. Can I create this relationship in LLBLGen even though it does not exist in the database so that I can use my RegistrationEntity to pull my AttendanceCollection? I would want to join the stu_id and cls_id columns together. IF this is possible, does it then generate all the PrefetchPaths as well? (crossing my fingers)

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 20-Apr-2005 20:11:35   

NickD wrote:

Five years ago I was the recipient of an existing data model. It was designed with best intentions, but we've all learned a thing or two since then, and I've discovered there is a poor relationship between two of my tables.

I deal with students, so students are registered into classes and then there is attendance taken for those registrations. However, due to some issues I won't get into, the relationship between Registration and Attendance is non-existant.

So, I have a stu_id and cls_id column in both tables, but they can not be foreign keyed. Can I create this relationship in LLBLGen even though it does not exist in the database so that I can use my RegistrationEntity to pull my AttendanceCollection? I would want to join the stu_id and cls_id columns together. IF this is possible, does it then generate all the PrefetchPaths as well? (crossing my fingers)

Assuming there is no logical reason the two fields cannot/should not be related (different data types, non-unique data on the PK side, etc) the designer can create "Custom Relations" on any two fields that fit the criteria. See the documentation "Using the Designer::Adding custom relations" for more information.

Jeff...

swallace
User
Posts: 648
Joined: 18-Aug-2003
# Posted on: 20-Apr-2005 20:42:31   

I've had great success in doing just that, creating relationships in the LLBLGen GUI where no relationship exists. I'm then able to use it exactly as though it were a real relationship, including using the Core.Manager templates (sweet...).

Be sure what ordinarily would have been the PK and FK are of the same datatype. If they aren't, I don't think it can be done.

NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 21-Apr-2005 00:43:29   

Thanks guys. I'll give that a try!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Apr-2005 10:23:45   

Thanks for helping out, guys simple_smile

The custom relations feature has been added just for this: when there is no FK present in the database, you still can add relations and use the full power of the generated code. simple_smile (and because I wanted to support MySql and MySql has FK's but I couldn't read them, I had to add this feature wink )

Frans Bouma | Lead developer LLBLGen Pro
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 21-Apr-2005 18:20:27   

Otis wrote:

Thanks for helping out, guys simple_smile

The custom relations feature has been added just for this: when there is no FK present in the database, you still can add relations and use the full power of the generated code. simple_smile (and because I wanted to support MySql and MySql has FK's but I couldn't read them, I had to add this feature wink )

Wonderful! Just the answer I was looking for.