Database Constants in a Class

If I have, say, a movie table, among other things, there is an int FilmTypeId field and a movie type table with an identifier and a meaningful description in the lines:

  • 1 - horror
  • 2 - comedy
  • ...

What is the best way to use this information in a C # class?

I would currently use them as constants in the helper class (unmistakably air code):

public class FilmHelper
{
    public const int HorrorFilmType = 1;
    public const int ComedyFilmType = 2;
    ...
}

but this does not seem to be supported. But I would like to avoid calling the database every time I came to use a constant or extra db call every time I used either helper or main object.

+5
source share
6 answers

Is the list of types fixed or is it changing?

, :

public enum FilmType {
   Horror = 1,
   Comedy = 2
}

. ( ) .

, , , - (, , , ). .

, , .

+5

.

class FilmType : Dictionary<int, string> {}

, .

, , .

+4

Enumeration,

public enum ReportStatus
{
    [Description("Reports that are running")] Running,
    [Description("Reports that are pending to run")] Pending,
    [Description("Reports that have errored while running")] Error,
    [Description("Report completed successfully.")] Finished
}

simliar Monsters Got My.NET. , .

+1

, .

+1

... , (, IDENTITY), StaticIdentifier THAT ( ). DEV, QA PROD, .

+1

, .

, , - script, . ( SQL script, # , .)

, , .

, , , , /, , script, ( , ).

+1

All Articles