When working with Microsoft Dynamics Nav (Navision), each company has its own set of database tables prefixed with the company name (e.g., ACME$Customer), which breaks standard Entity Framework usage. After exploring failed approaches — passing a table prefix to DbContext and using DbCompiledModel — the author settled on a solution using dynamic C# code compilation at runtime. A CommonDBContext abstract class holds DbSets and model mappings, while a DynamicContext class dynamically compiles a concrete subclass per company and caches the result, avoiding repeated compilation overhead. This allows EF to target company-specific tables without requiring recompilation or redeployment when new companies are added.

5m read timeFrom nodogmablog.bryanhogan.net
Post cover image