0 Replies - 5712 Views - Last Post: 19 September 2012 - 01:06 PM Rate Topic: -----

#1 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Entity Framework Code-First Issue (SimpleMembership)

Posted 19 September 2012 - 01:06 PM

If you've used ASP.NET MVC 4 you'll notice that the default for an Internet Application is to use the SimpleMembership provider, this is all well and good and works fine.

The issue comes with the default database generation, they have a POCO for UserProfile defined like so:

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
    }


.. which is then generated like this:

    using (var context = new UsersContext())
    {
        if (!context.Database.Exists())
        {
             // Create the SimpleMembership database without Entity Framework migration schema
             ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
        }
    }


This works fine, the database is generated just fine and works without issue. However, if I am to change the POCO like this and delete the database:

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string EmailAddress { get; set; }
        
        public string FirstName { get; set; }
        public string Surname { get; set; }

        public string Country { get; set; }

        public string CompanyName { get; set; }
    }


Only the first 2 columns are generated, UserId and EmailAddress. It works just fine code-wise (talking login/registration), but obviously none of my other user data is stored.

Am I missing something here? Surely it should generate the database based off the whole `UserProfile` object.

This post has been edited by RudiVisser: 21 September 2012 - 05:37 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1