none
Using VS 2012 with VS 2010 project and EF 4 is generating extra columns when using code first. RRS feed

  • Question

  • Hi, I just installed VS 2012 Premium and I've been following along with the PluralSight ASP.Net MVC 4 Tutorial. I'm on chapter 4 and the project creates a database automatically using EF 4 Code First.

    The strange thing is that it creates extra database columns rather than matching the properties in my Restaurant.cs model file.

    In Restaurant.cs I have:

    namespace OdeToFood.Models
    {
        public class Restaurant
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public Address Address { get; set; }
        }
    }

    However, in the OdeToFoodDB dbo.Restaurants table it generates:

    • ID (PK, int, not null)
    • Name (nvarchar(max), null)
    • Address_Street (nvarchar(max), null)
    • Address_City (nvarchar(max), null)
    • Address_State (nvarchar(max), null)
    • Address_Country (nvarchar(max), null)

    but there are no Street, City, State, and Country properties in the class. In the video the database only has the ID, Name, and Address columns, but I don't know if that might have to do with the fact that he was using EF while it was in the prerelease state.

    Does anyone have any ideas what is going on here?

    I've already deleted the generated database, files in obj and bin, recreated a Restaurant.cs class, uninstalled EF4, and added EF5, but nothing has changed the end result.


    Wednesday, September 5, 2012 3:51 AM

Answers

  • Hi EinDoofus,

    Welcome to the MSDN forum.

    I have gone through the video tutorial you mentioned. At the start of the video, the author deleted the properties city, state, country and imageurl and renamed the streetaddress to address. Please note the type of address is String instead of Address in your post.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Wednesday, September 19, 2012 7:02 AM
    Thursday, September 6, 2012 5:37 AM