1

I have to model and manage a time-based configuration. Typically - without an OR mapper - I would start with the database tables.

Screen            Color        ColorScreenMapping
-------------     ----------   --------------------------------------------
id | name         id | name    valid_from | screen_id | color_id | disabled
1  | screen 1     1  | red     1.1.2015   | 1         | 1        | 0
2  | screen 2     2  | green   3.1.2015   | 1         | 2        | 0
3  | screen 3     3  | blue    7.1.2015   | 1         | 3        | 0
                               1.1.2015   | 2         | 1        | 0
                               5.1.2015   | 2         | 2        | 0
                               9.1.2015   | 2         | 2        | 1

Then I would model two classes: Screen and Color. The database query would ensure that for a given date each screen has exactly one color object associated (1-N relation).

The downside would be that changes to the configuration would only be possible at the database level and not in the C # model. (There would be no valid_from property in the model.)

How would a suitable model look like for the code-first approach?

Would it be wiser to start with my database and use the db-first approach?

1

If you want to have a valid_from property in C#, then you should model it in C#.

You suggest an implementation and conclude what requirements could (and could not) be fulfilled with this implementation. That puts the cart before the horse. Start with your requirements, then come up with an implementation.

How would a suitable model look like for the code-first approach?

This depends on what you want to do with that model. What information do you need in C#? A model that is suitable will contain all that information.

  1. Maybe you only want to retrieve the current screen-color mapping. In this case C# needs no valid_from, because this information is implicitely gien by when the request to the DB is made.
  2. Maybe you want to add new screen-color mapping from C# to the DB. In this case, you need to explicitly specify the value of valid_from for each new entry and you should model it in C#.
| improve this answer | |
  • I think I need booth: 1) When usinge some kind of main module of the software, then the date isn't important. 2) If using some kind of configuration module valid_from is important. – user183745 Jul 16 '15 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy