Question

In our project, we have many small programs spread across multiple computers, each responsible for a specific tasks against the legacy database. Today, they are written in Fortran 77 and uses a very outdated framework for database access.

We are thinking of start developing in C# and investigate how we best can create a database framework that all applications can use. We can not use any existing frameworks when the old realtime database does not support SQL.

I am thinking of generate a DAL with T4 from the database definition. The problem I see however is what happens when the database changes and DAL must be recompiled. Is it enough to copy the dll file containing the DAL to all computers, or do we have to recompile to applications?

The actual structure of the database does not change so often. However, a lot of lookup constants is changed regularly. Normally, no constants is deleted, but they can get new values ​​or new ones can be added. And if there is any constant that is removed, the programs that are using it must anyway be rewritten.

I fear that it may become a maintenance problem and looking for a better solution.

Edit

Primary keys are not constant in the database, but are regenerated once a year. To make programs able to find the correct row in the database, lookup constants is used. In existing programs, the constants are used directly in the code in the form <TableName(RowName)>. The constants is then replaced to the current primary key value by a preprocessor. This means that all applications must be recompiled when the database is rebuilt.

It is therefore not possible to use e.g. GetByKey(int key) in BLL as the key is not constant. I see a number of different solutions to this as listed below, which are good and which are bad? Please tell me if you see any other better solutions:

  • Define lookup constant in the DAL:

    BLL.TableName.GetByKey (DAL.TableNameLookup.RowName)

    • Pros: The constant i defined in DAL and I don't have to replace BLL if the lookups is changed.
    • Cons: Verbose syntax
  • Define lookup in BLL:

    BLL.TableName.RowName

    • Pros: Simple syntax
    • Cons: I have to update BLL when the lookup constants is changed.

This might be solved both with code generation (T4) and DynamicObject. Om DynamicObject is used, the constants maybe can be defined in an XML file that can be easily updated. However, it will be significantly slower.

I do not think any of these ways is good. Please help me to come up with something better.

Was it helpful?

Solution

Use the One more Layer between DAL and Application.(ex: BL-Business Layer)

Call the DAL layer methods in BL and From Application call the BL Layer. Doing this you can avoid the dependency between DAL and Application. Then when ever you do changes in database only change in DAL Layer and Replace the dll. No need to compile the application on every change in DAL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top