What happens when the migration scripts execute?

2 posts, 0 answers
  1. Anwar
    Anwar avatar
    14 posts
    Member since:
    Oct 2012

    Posted 12 Jan Link to this post

    I am moving to the latest Telerik Data Access using the fluent API. I have been using the tutorial provided here: http://docs.telerik.com/data-access/getting-started/getting-started-fluent-mapping-overview.

    At the end of the tutorial, it is mentioned that you need to initialize the db using a migration script. In my case, I already have an existing db with a preexisting schema and I am mapping my persistent classes to this db. What happens exactly when I run the migration script detailed in the EnsureDb method? I don't want the db schema to be changed in any way.

     

    Also when I build my library project and the client project, Telerik Data Access complains about not discovering any persistent classes (No persistent classes found. Is the metadata information missing?). At runtime the app crashes with the following exception: System.ArgumentOutOfRangeException:Type is not [Persistent] or the assembly was not enhanced by OpenAccess

     

    Thanks for your help!

  2. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 15 Jan Link to this post

    Hi Anwar,

    On your questions:

    1. What happens exactly when I run the migration script detailed in the EnsureDb method?
    The method does a few things depending on the scenario:
    a) If the database specified in the connection string exists on the server and is empty the method generates (and at its end executes) DDL script for the tables based on the mapping of the classes in the model. This is called the model-first approach or the forward-mapping approach. 
    b) If the database specified in the connection string exists on the server but contains tables, the method will calculate the differences between the content of the database and the mapping of the classes, and will generate (and at its end execute) DDL script that applies the changes from the model to the database.
    c) If the database specified in the connection string does not exist on the server, the method will create it and will execute the first of the scenarios described above.

    If you do not want changes in the schema of the database on your side, I would suggest the following:
    1. Create a database for testing purposes,
    2. Specify its name in the connection string consumed by your model,
    3. Execute the method using this testing database,
    4. Compare the new database with the original one,
    5. Adjust the model where necessary so that the script it produces matches the database.

    Regarding the warning (No persistent classes found. Is the metadata information missing?) it appears when the Fluent NuGet package is installed on a project that does not have persistent classes. If you uninstall the Fluent package and install only the Core package on your projects that consume the model, the warning will disappear. 

    As for the error on startup, I would suggest to you the following test:
    1. Open the project file of the project that holds the model and verify that the following line is available close to its end:
    <Import Project="OpenAccessNuget.targets" />
    2. Uninstall the Fluent package from the projects that consume the model and install the Core package on them.
    3. Clean-up the solution and rebuild it.
    4. Run the application for a test.

    If the error appears again, the following information will be appreciated:
    1. Is the class for which it appears part of the model (is it a persistent class) or it is a part of the projects that consume the model?
    2. Which .NET technologies do you use in your solution?
    3. The steps (both configurational and runtime) that lead to the appearance of the error.

    I hope you find this feasible.

    Regards,
    Doroteya
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
Back to Top