DAL, Business Entities - Where does logic for mapping go

Topics: General Discussion Forum
Mar 24, 2007 at 10:04 AM
Okay here's a simple question of design.

When I have a simple class such as a Ticket class and that class has a field which is a user type. The database table Ticket has a fireign key relationship to User and a field called USerId. In my DAL I have access to the UserId class but my Business Entity requires a User class.

I have two basic options.
-1. Should I change the business entity (this seems bad) to store the userId and the property for User can return the user business object.

private int userIdField;
public User AffectedUser
get{return Framework.GetUser(userIdField);}
set{userIdField = value.Identifier;}

-2. Should I alter the DAL Factories to call into my BLL to set the property
Ticket.AffectedUser = FrameworkFactory.User(userIdentifier);

If I change my DAL i'll beng having to change it as often as I regenerate by DAL.

Is there any method provided by the guidance package that people would recommend?

Mar 24, 2007 at 11:20 AM

Exercise 5 and Exercise 7 in the Hands-on-lab focuses on this problem.
Mar 24, 2007 at 2:30 PM
So does that mean that you think it is best for me to use the partial class concept for my Foregn Keys and implement my translations and loading for the Select objects in the Data Repositorys. I understand the example but the problem I think is slightly different for a select than an insert. For insert I already have the object so calling the Country field in WinePreference make complete sense.

e.g. ClubMember.WinePreference.Country

but when using the DataRespository to do a select one, for example, I need to

ClubMember.WinePreference = new WinePreference(winePreferenceId);

I know wine preference doesn't have an id field but its only an example. I hope that makes sense. THe FK relationship in the database for WinePreference table would result in a winePreferenceId stored for a customer not the actual values.

Thanks so far .... SCott