Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm updating really old VB.NET legacy code to a more testable MVP/MVVM pattern. I'm not very experienced with Entity Framework, but I'm slowly getting more and more acquainted with it. However, the following anti-pattern from our database is confounding me to no end, and I'd appreciate some insight.

I have a large table, lookup_table, with the following design:
SQL
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[TableType] [varchar](20) NOT NULL,
[TableCode] [varchar](20) NOT NULL,
[TableDesc] [varchar](250) NOT NULL,
[CodeDeleted] [bit] NOT NULL,
[TableOrder] [numeric](10, 0) NOT NULL

Other tables reference values in this table by TableType and TableCode, and get the user-readable TableDesc. For example I can have a table for Offices with columns:
SQL
OfficeStatus [lookupType] NOT NULL,
OfficeType   [lookupType] NOT NULL

OfficeStatus would use values from
SQL
SELECT TableDesc, TableCode FROM lookup_table 
WHERE TableType = 'Status' AND CodeDeleted = 0 ORDER BY TableOrder
to fill in combo boxes using TableCode and TableDesc as the code and display text, respectively. Something similar would be done for OfficeType by just changing
SQL
... WHERE TableType = 'OfficeType' ...

The predicament is that importing lookup_table as an entity seems to not let me limit the rows returned to a specific TableType.

I've tried setting up T4 templates to return enums with attributes so I can keep the columns for TableOrder, TableCode, etc., but these enums lose the ability to be able to add a lookup_table value without having to rebuild the application.

I would like this preliminary test MVP application to be able to refer to these lookup values so I can have a conditional on the OfficeStatus as:
C#
if OfficeStatus.Active { ...

but so far, I haven't been able to find a simple way to do it using Entity Framework. If you have experience using EF, what can I do differently or what should I be reading up on to solve my problem?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900