Wednesday, May 11, 2016

Re-generating an ADO.NET Entity Data Model from the database

I recently had to change my underlying database schema and therefore needed to update my Entity Framework Data Model.

Unfortunately, just updating the data model directly caused problems with column mappings, so I ended up having to regenerate the ADO.NET Entity Data Model.

Going through the Visual Studio Entity Data Model wizard went through just fine, however, because of the structure of the project/solution, I quickly discovered that I could not name my entity class the same name as before!

Instead, my class name was showing up as "Entities" instead of my original class name!

Well, thankfully, changing the name of the class was relatively easy by simply modifying the <EFModel>.Context.cs class file.

public partial class Entities: DbContext
        public Entities()
            : base("name=Entities")

I then simply changed this to match my Entities class name as follows:

public partial class MyCustomEntities: DbContext
        public MyCustomEntities()
            : base("name=MyCustomEntities")

Now I could work with my Entity Framework classes just as before!!

1 comment:

  1. Really an awesome post. I wondered by reading this blog post. Thanks a lot for posting this unique post which you have shared with us. Keep on posting like this exclusive post with us.

    Hadoop Training in Chennai