none
Reinitializing the localDB RRS feed

  • Question

  • I have been following a VB ASP How-To.  Part of the how to is to use the entity framework code first model. I added an attribute to the class.

    I get an error now stating my class does not match the database.  I tried to find a VB example to reinitialize the database but all I was able to find was C# examples.  I tried to convert the C# code but was not successful.

    My question is what statement(s) do I need to re-initialize the database and where does that code need to go.

    Thanks.

    Friday, December 26, 2014 5:17 PM

All replies

  • Hello,

    I am moving your question to the Entity Framework forum as this is more specific to EF.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, December 26, 2014 9:43 PM
  • Hello Kazinski,

    >>I get an error now stating my class does not match the database. 

    Do you mean that the database is already created and you add an attribute to the class, the project throws the error?

    Since you use the code fist, the Entity Framework would compare your model with database to check if they are matched everytime the project starts, a proper way to process this scenario is to use code first migration to migrate your any changes to the database:

    http://msdn.microsoft.com/en-us/data/jj591621.aspx

    Although it uses the C#, the migration command is same even with VB.

    >> My question is what statement(s) do I need to re-initialize the database and where does that code need to go.

    One way is to use the migration as I mention above, you could create an initial migration to drop your database to the original one.

    Another way is to delete your database(and migrations folder if you enable the migration), remove your added attribute and run your application again.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 29, 2014 2:51 AM
    Moderator