I have a situation where a DB field is storing an enumeration value whose underlying type is int
, so I'm getting back values like 0, 1, and 2, which should represent MyEnum.Foo
, MyEnum.Bar
, and MyEnum.Baz
. I am calling a repository which returns DTOs in order to get a DTO which contains this value. My question is, where should this int be converted to the enum?
My solution has 3 layers: I call them Data, Infrastructure (basically business logic), and Web (basically presentation). As far as I'm aware, the Data layer shouldn't be aware of the BLL layer (ie. Infrastructure), and yet I'm storing the enumeration in Infrastructure - it is, after all, business logic that 1
means Bar
, or whatever.
So I can't do my conversion in the Data layer. Am I supposed to get the int
returned by the Data layer from the Business Logic Layer, map it to a BLL object, and do the conversion while mapping? So the mapper would convert the int
on the Data DTO to an enum
on the BLL model object? Or would it be acceptable for my data repository to just reference Infrastructure.Enums
(or wherever I store the enums) and provide a field in the DTO it returns of that enum type, meaning that the mapping would happen in my Data.Repository
project?