I've created a 3 layer implementation; presentation, model or business logic, and data layer. I have several Models which desribe my data and am trying to determine the best way to create properties around my data values. The catch is the values I get from
the database is not what I want to display to the user. For instance, If I get a value of 'TD' I want to display "Total Amount Due".. All my fields have lookup values, I know what your thinking - but its a legacy system. I wasnt sure what the proper way to
do this was because I've discussed this with several individuals and each answer is different for the getter or setter. Some say to convert the value in the getter, others say the setter.
//This section gets implemented in data layer
//Getting data from Database using a database object named data and setting value to my Model Object, myObj
myObj.Status = data.Status;
myObj.Type = data.Type;
myObj.Category = data.Category
//This section gets implemented in business layer; try to determine how I set my public members/properties correctly.
private string _Status;
private string _Type;
private string _Category;
public string Status{get;set;}
public string Type{get;set;}
public string Category{get;set;}
I always perfer to set my values when they're retrieved to limit the amount of code on my page. I'm going to assume you're using a SP to pull the values from your DB. Are the values you're pulling from the DB a small finite list? If the list of possible
returns is small I would format the results with a case statement. NewField = Case When Field = 'TD' Then 'Total Amount Due' When Field = 'Other' Then 'Some Other Values' ..... End
If you're dealing more then just a handful of possible values, then I would suggest creating a secondary table with one field as the result from your first table and a second as the text you want to display and joining.
The biggest problem with trying to format your text when you set it versus when you get it is future changes become harder to manage. If you're formatting when you get your data you can easily add values to your database without having to recode your page.
Especially if you use a secondary table and create a join so you pull the text you want to present to the user. And if at some point you want to change the text you present again you just need to modify the text you have stored in the database, you don't
have to recode your page to accomplish this.
Marked as answer by FunkyMonk81 on Apr 30, 2012 05:53 PM
FunkyMonk81
Member
109 Points
89 Posts
Properties Values
Apr 27, 2012 01:12 PM|LINK
I've created a 3 layer implementation; presentation, model or business logic, and data layer. I have several Models which desribe my data and am trying to determine the best way to create properties around my data values. The catch is the values I get from the database is not what I want to display to the user. For instance, If I get a value of 'TD' I want to display "Total Amount Due".. All my fields have lookup values, I know what your thinking - but its a legacy system. I wasnt sure what the proper way to do this was because I've discussed this with several individuals and each answer is different for the getter or setter. Some say to convert the value in the getter, others say the setter.
//This section gets implemented in data layer //Getting data from Database using a database object named data and setting value to my Model Object, myObj myObj.Status = data.Status; myObj.Type = data.Type; myObj.Category = data.Category //This section gets implemented in business layer; try to determine how I set my public members/properties correctly. private string _Status; private string _Type; private string _Category; public string Status{get;set;} public string Type{get;set;} public string Category{get;set;}chiragtoad
Member
212 Points
51 Posts
Re: Properties Values
Apr 27, 2012 01:20 PM|LINK
Is it in MVC or normal 3Tier architecture?
FunkyMonk81
Member
109 Points
89 Posts
Re: Properties Values
Apr 27, 2012 01:20 PM|LINK
Normal 3 Tier
Loganix77
Participant
1351 Points
412 Posts
Re: Properties Values
Apr 27, 2012 01:21 PM|LINK
I always perfer to set my values when they're retrieved to limit the amount of code on my page. I'm going to assume you're using a SP to pull the values from your DB. Are the values you're pulling from the DB a small finite list? If the list of possible returns is small I would format the results with a case statement. NewField = Case When Field = 'TD' Then 'Total Amount Due' When Field = 'Other' Then 'Some Other Values' ..... End
If you're dealing more then just a handful of possible values, then I would suggest creating a secondary table with one field as the result from your first table and a second as the text you want to display and joining.
The biggest problem with trying to format your text when you set it versus when you get it is future changes become harder to manage. If you're formatting when you get your data you can easily add values to your database without having to recode your page. Especially if you use a secondary table and create a join so you pull the text you want to present to the user. And if at some point you want to change the text you present again you just need to modify the text you have stored in the database, you don't have to recode your page to accomplish this.
FunkyMonk81
Member
109 Points
89 Posts
Re: Properties Values
Apr 30, 2012 05:53 PM|LINK
Shouldnt be a problem..since I'm only retrieving data with these specific values..Thanks!