Giter VIP home page Giter VIP logo

entityframework.verify's Introduction

EntityFramework.Verify

Generic library to verify an entity model matches a database for the provided Context type.

Introduction

After using Entity framework with legacy systems, I encountered an issue with customers making modifications to databases that created a mismatch between the entity model we developed with and the database. Changes that rendered them unusable by entity framework. This library compares the entity model with the SQL database it's been deployed to, and generates a detailed report that outlines missing columns and tables. I describe the problem on this Code Review question.

Usage

  1. The library is easy to use, once referenced you simply create an EntityFrameworkTypeRepository constrained to your DbContext:
    // With support for Linq2SQL and multiple connection strings    
    // for entity framework DbContext
    var entityRepo = new EntityFrameworkTypeRepository<SomeDbContext>();
  • For Linq2Sql where there is no centralised data context with a list of tables, it is necessary to reflect on the entity classes based on their attributes. The Linq2SqlTypeRepository is a helper class that provides an example of extracting entities.

  • Usage is similar to the previous Entity framework example:

   // get the assembly containing the entities
   var assembly = typeof(SomeEntityClass).Assembly;
   // build a Linq2SqlTypeReporitory with that assembly
   var entityRepo = new Linq2SqlTypeRepository(assembly);           
  1. Create a table factory based on one or more connection strings
    // build a table factory from the SQL connection strings
    var tableFactories = new MultiConnectionSqlTableRepository(connectionString1, connectionString2);
  1. Create a model verification and generate the report object
    // generate the report
    var verification = new ModelVerification(entityRepo, tableFactories, 5);    
    var summary = verification.GenerateReport();
    // build a report with the summary
    var report = ModelVerification
        .BuildMessage(title, database, summary.Where(s => string.Equals(s.Database, database) && s.HasMissingColumns));
    Console.WriteLine(report);

The results from this operation is a summary repoprt (IEnumerable of summary objects). It can be output as plain text, or presented as a lookup. I use an accordion in my web applications to present it visually, but simply log verification errors at stratup. The report is presented as text with the missing tables listed first, followed by the tables with missing columns -

DatabaseName** Has some errors: 
    Missing tables: 
        Table 1
        Table 2
    Table 3 With Missing Columns: 
        missing column 1
        missing column 2
    Table 4 With Missing Columns: 
        missing column 1
        missing column 2
        missing column 3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.