Getting String Sets into Presentation Layer

Freelance Jobs

We're working on an hospital information system that is being written on C# and using NHibernate to map objects to database. MVC pattern is being used to separate business logic from UI. Here is the problem,

How do you get variable sized different set of strings to UI?

For example a Contact object have a property named City that holds which city contact lives. In country that the app is written for has more than 80 cities. How could you write those cities to a combo box? (or a data grid, tables, ...) In this example the city number is fixed. There is no need to add another city for a long time. (If the city list changes, recompiling is not a problem)

For example a Contact object have another property named FooBar which is going to be hold 1000 different string values and these values is going to be selected from a combo box for that property. And this set can be grown if users want. How do you load the combo box with these values? (If the string list statically written to combo box object, recompiling is a problem)

I have different solutions as below

  1. All string values statically written to combo box in code or designer
  2. Get the values from a resource file
  3. Write those values to an XML file (Actually same as above, but no need to recompile)
  4. Make a City object and get the values into a list from CITY table with NHibernate
  5. Make a class named StringHolder which has a Type and Value property. All string values(including City and FooBar) would be written in just one table named STRINGHOLDER. And get those values with a key like "CITY" or "FOOBAR" with NHibernate.

Which one would you choose? Or could you suggest me another one?

Thanks all

2008-10-20 12:52:45 Scores:0

3 answers

Answer 1

I would vote for solution #4. That's the way I have always done it in similar situations. It just seems like a cleaner solution.

Anson Smith H
2008-10-20 13:01:47
But City is going to hold just a string. Do you think it is right for domain model? public class City{ private string _name; public string Name{ get {return _name;} set {_name = value;} } } There is going to be many classes like this if i don't use inheritance.
xelon H
2008-10-20 13:27:54 Scores:0
If i use inheritance there is going to be many empty classes like Contact, FooBar etc.. What do you think?
xelon H
2008-10-20 13:28:53 Scores:0
If City is just going to hold a string and never be used for Anything else then a Table may be overkill. But, many times once code is in production you may find new uses/needs for it. I personally use lookup tables/Domain objects for entities like city (States, Countries).
Anson Smith H
2008-10-20 13:48:29 Scores:0
There is going to be so many string sets like this. Solution #4 will take too much to make for too many entities. I think we'll going with #3 and see if it works or not. But as i said string values(instead of integer keys to those values) will take too much space in database with #3. Thanks again
xelon H
2008-10-20 14:14:09 Scores:0
Answer 2

If the locations are actually going to be used for anything, get them into the database. If the data "isn't really used", but cities lookup is provided to make the user interface better, then the XML file option is not a bad way to go either.

By used, I mean stuff like list all emplyees in New York and stuff like that. If it's "dead data", just to be displayed, go for the solutions that will require the least amount of work and least risk - which might be the file option.

Torbjørn H
2008-10-20 13:16:52
For example every Contact added to database has a City and FooBar field which is coming from combo boxes. So it's not that dead :) In some string sets some of the string values has more than 100 characters. For every contact a row added and all rows will take 100 chars for just one field.
xelon H
2008-10-20 13:37:53 Scores:0
If i make it like this there is a "normalization" problem. Most of the rows in a table will going to have same value on FOOBAR field. If i make classes for each string value sets, domain design will going to be messy :) Both have advantages and disadvantages. What do you say?
xelon H
2008-10-20 13:42:48 Scores:0
I stick with what I said. Your domain model should ideally don't care one bit about how the database looks btw, the domain classes should look the way you want your code to work. But if you store the cities in db, I would normalize and have a separate city table with id's.
Torbjørn H
2008-10-21 10:44:55 Scores:0
Answer 3

How do you feel of using List<string> for a list of City? Load this list of strings in your DAL or BL and then pass it on to UI.

Same solution should be good for FooBar values too.

In case you have IDs associated with City or FooBar, say NY and its numeric ID in DB is 1, then you can use KeyValuePair<TKey, TValue>. With generics you can dictate what data goes in this KeyValuePair. City name or FooBar's string value can be key and numeric ID can be value.

Just 2 cents.

Pradeep H
2008-10-20 17:54:18
Share |
View original post at

Related topics

Presentation, Business and Data Layer

I just started programming in C# and was reading about dividing your application / website into the three different layers was the best practice but I am having a hard time understanding exactly how. Im working on a pet project to lean more about C# but I dont want to ...

Getting a business layer to communicate with presentation

So I'm working on a small TicTacToe application over the holidays to improve some of my skills. I have a two layered approach right now where there is a project for the presnetation and a project for the business end of the game. My question is what is the best ...

Presentation layer architecture in an enterprise application

At our company we are developing an application that will consists of several modules. The architecture is pretty much defined but I have seconds thoughts about the presentationlayer and I would really like to hear your opinions. The architecture is as follows: Foreach module we create several namespaces and those will ...

Designing a system with a presentation layer and a web service-based API

We are designing a system that has functionality that is essentially the same at the presentation layer and the exposed API layer. My question is what technique / strategy to use so we can get the most reuse out of our code with performance in mind? Here's a simplified example: A user ...

ASP.NET MVC: How can I get my business rule validation to bubble up to the presentation layer?

For each of my business entities I have a corresponding view model. I have a generic CRUD controller that works like this: [HttpPost] public virtual ActionResult Create(TViewModel model, int? id) { // Validate input ...

Separating business logic dependent on web references out of presentation layer

I have a web app with a presentation layer and a business layer as individual projects. One being a web application and the other being a class library. I have added a web reference to the web application to use a web-service. I am having no trouble using the service ...

Hiding Entity Model classes from Presentation Layer

I am developing web forms app in C# Framework 3.5 I want to build something like "Presentation > BLL > DAL > Entity Model" flow in my application. But problem is this that, how will I use entity objects in Presentation layer? Suggestions? ...

which tiers should i catch exception when using DAL BLL and web Presentation Layer

I write a three tiers web application. DAL BLL and web Presentation Layer,every tier has methods , so the question is where should I catch exception( using try catch),in web?BLL?or DAL? and why? thank you. ...

Should my Presentation Layer create a session in NHibernate?

I'm learning NHibernate and have created some unit tests and it's going quite well. My main app only has two layers: Presentation (WPF app) Domain (has business logic and data access) and of course I have my Unit test project (Test). My unit tests call my SessionManager class to build a SessionFactory ...

Should i use Entity Framework entities in my presentation layer?

I want to create a multi layered (3 layers) application. EF is the preferred ORM of choice. Should i use the entities that EF creates directly in my presentation layer, or should i create new custom entities and map the entities? If so, should i create interfaces on top of ...