How to change the database structure
Zonal OCR uses a file-based SQL CE database stored on the user's computer to persist templates, fields, etc. If you need to make a change to the structure of the database (tables, columns, or whatever) follow these instructions.
Update the UpdateDbTool project
UpdateDbTool automatically runs on the user's machine every time they install a new version of Zonal OCR. First, we need to update the tool toso knowthat it can detect if the user's database requires an update, and then how to apply that update.
- general approach
UpdateDbManager.cs- is
- to
create an alter statement createexecute a querythattodeterminescheck ifthe database is at the new versioncreate a function that calls your alter statement(s)add a version that that calls your previous function
- to
- installer
This tool will updatethe user's databasewhenneedstheyaninstallupdate and, if so, execute the commands to change the database.Example
As a specific example, here's how you would modify UpdateDbManager.cs to add a newversionExcludeFirstPage column to the existing Forms table. (This example assumes this will be the 6th time we've updated the Zonal OCR database since its initial release.)- Add a string property to the class called AlterFormsAddExcludeFirstPage that contains an ALTER statement that, when executed, adds the column to the table.
- Add a string property to the class called CheckVersion6Installed that contains a query that, when executed, checks if the ExcludeFirstPage column exists in the Forms table.
- Create a PrepareUpdateQueriesVersion6 method that adds the AlterFormsAddExcludeFirstPage property to the list of
Zonal.queries to be run. - In the PrepareUpdateQueries method, write a conditional that calls the CheckVersionInstalled method, passing the CheckVersion6Installed string as an argument, to determine if the database needs updated.
- Inside the conditional, call your PrepareUpdateQueriesVersion6 method.
Apply Changes
To test yourchanges,code and apply the changes to your local installation of Zonal OCR, you can simply set the UpdateDbTool project astheyour startup project in Visual Studio and runit.theProbablysolution. (You may be prompted to re-open Visual Studio as an administrator.) You do NOT need tobecreateinaadminnewmodejust
The
Apply migration to the empty database
- Update copy of ZonalOcrDb.sdf
Update the ZonalOCR project
-
DataAccess
-
ZonalOcrDb.edmx.sql - update initial creation queries
-
ZonalOcrDb.edmx
-
<edmx:StorageModels> -> <EntityType>
-
<edmx:ConceptualModels> -> <EntityType>
-
<EntitySetMapping>
-
-
Update models in /EntityModel/
-