Starting point
(changing some real naming, just to simplify)
The project consists of an ASP.NET MVC 4.7.2 application, with a SQL Server database. The MVC app uses Entity Framework 6, with an entity data model (initially based on database-first model) for current database that generate the classes to manage the database entities.
The objective of the application is to create and digitally sign document instances based on different kinds of documents. The generated instances are simply PDF files.
This database has a table (Instance) that stores each instance file (PDF) as a varbinary (column File), among other instance metadata (creator, date, name, department...), with a unique ID as primary key named InstanceId.
Each instance is created and modified a few times, depending on document type and digital signature requirements. These iterations must take from a day to a year. After finished and completed the digital signature process, the instance would be kept in database for a long time, and the file won't be modified anymore.
After some time (casuistry could vary from 2 to 5 years, depending on base document type), files could be deleted, as some are already stored in a document repository and other are discarded as obsolete.
Problem detected
The amount of files is massive nowadays, and keeps growing up by leaps and bounds. That makes the database hard to manage (backups, synchronization with testing development environments...)
Potential solution
The mainly accepted approach is to keep current database (MYAPP) with same table Instance storing all metadata for each instance created, and create a new database (MYAPP_FILES) with a unique table (also called Instance) that stores only the files (PDF in varbinary column).
The link between tables should be using the same ID in both tables, something like MYAPP.Instance.InstanceId = MYAPP_FILES.Instance.InstanceId.
Creating a view (also proposed in other posts, like Entity Framework with multiple databases) based on Instance table. Using original table to work with it for transactions (create, update), and take the view for queries (depending on date, this could retrieve File column from MYAPP or MYAPP_FILES using the InstanceId to relate both databases/tables).
This requires creating a new entry in the MYAPP_FILES Instance table, based on date column, for some instances. This could be achieved using a SQL Server Agent job scheduled to execute periodically.
Questions
- Creating a new EDM to refer and work with MYAPP_FILES database means a lot of effort but, does it have other benefits?
- Is there a better solution in terms of efficiency/best practices?
- Once created in current EDM, the view does not contain, of course, navigation properties. Is there a way to generate them using EF?
- Once created both classes to work with (let's suppose,
Instance.csandViewInstance.cs) is it possible to use the first for creating / updating actions and the second for queries using repository pattern?