Entity Framework database-first - dynamically adding table to model

c# ef-database-first entity-framework-6

Accepted Answer

I added a column for the code prefix and triggers for insert, update, and delete to my base table business to address this issue.

1
1/27/2018 1:25:14 PM

Popular Answer

It would be far preferable to reorganise the database to a single table, as the other commentators have said. The only other option I can think of if you are unable to accomplish that is to have a class that will choose the table for you.

I would design a new class that has the descriminator property as well as the same attributes as your company's tables. The data source for your user interface would then be this.

In this class, depending on the result of the discriminator, you would have to manually code to pull the data from the appropriate real table (and write to it). This is acceptable if you just have a few tables, but as the number of similar tables increases, the problem will become worse.

You could design a dictionary that the base class could use to swap the ultimate data source on-the-fly if it were feasible for the base tables to all inherit from a virtual base class.

Have you given any attention to: 1. Creating the master table as a single table, as mentioned by the other comments, and then having views for each firm.

  1. Making the master table as advised, and then having code to make the individual tables from that one at some time before they are used?


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow