The legacy database I work with has a table with some sample information shown below:
LiabilityType
134
137
140
143
146
999
001
003
006
009
These codes actually contain two bits of information:
- Whether the debt is classified as an expense or liability (if code starts with '1' -> expense; if it starts with '0' -> liability
- The type of debt (e.g. mortgage, funeral expense, overdraft etc)
As such, I would like to map this field to two properties in my entity.
I have looked at ICompositeUserType, but this appears to be about mapping two fields to one (composite) property, not mapping one field to two properties.
I can see how I can create two classes implementing IUserType which examine this field and convert it to the correct property values, but I can't work out how the class would convert the properties back to the appropriate database values. For example, I would like to map this such that I can create a linq query where I can say;
.Where(x => x.ExpenseOrLiability == ExpenseOrLiability.Expense)
and this will be converted into SQL like the following:
WHERE LiabilityType LIKE '1%'.
Is such a thing possible?