[RESOLVED]Why won't Mvc 4 application pick up email column added to UserProfile table ?

As the question suggests I added an email column to the UserProfile table. (As I need a valid email address for each user) However when I try to access this in a "Lost Password" feature, I get the following error.

 {"The column name is not valid. [ Node name (if any) = Extent1,Column name = UserEmail ]"}

The code block in the my LostPassword Action in my Account controller.

// can't access UserProfile table with Email value
                var foundUserName = (from u in db.UserProfiles
                                     where u.UserEmail == model.Email
                                     select u.UserName).FirstOrDefault();

In my InitializeSimpleMembershipAttribute_

WebSecurity.InitializeDatabaseConnection("EFDbContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);

In my Account Models -

public class UsersContext : DbContext
    {
        public UsersContext()
            : base("DefaultConnection")
        {
        }

        public DbSet<UserProfile> UserProfiles { get; set; }
    }

My EFDbContext is made up of -

  public class EFDbContext : DbContext
    {
        public DbSet<Product> Products { get; set; }
        public DbSet<Orders> Orders { get; set; } 
    }

And I have no problem accessing these tables .

When a user registered , the following is used-

WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { UserEmail = model.UserEmail });

My database base in SQL is called MerchandiseProject

How can I get application to recognise the email column to check against users input. Please note this is an MVC 4 application built with VS 2010 and using Simple Membership. Thanks.

Have you refreshed your edmx file after adding the new column?

no I didn’t , how do I refresh it ?

(where is it located)

I don’t have an edmx file and I’ve being working with this database for a few days, including adding to the email column.

How r u accessing the database. In case you are using the EFF try to update the edmx file. 

I anticipate you are following a database first approach. So check for the .edmx file in the Models folder, if you are not following any architecture. You get the design of the database here. 

After that right click and select update model from database. This will update your entities. Then go to the .tt (T4 template) file right click and Run custom tool. This refreshes the entities properties added newly to database.

Check for this. I hope this should reflect the email property.

Thanks.

Hi mkell81,

Thanks for your post.

Based on your description,you want to add an email column to the UserProfile table.

Firstly you  need to install these two packages:-

Microsoft.Aspnet.Identity.Core

This package contains the core interfaces of ASP.NET Identity.

Microsoft.Aspnet.Identity.EntityFramework

and more information,you can follow these steps:

#Customize User’s Profile in ASP.NET Identity System

http://www.itorian.com/2013/11/customize-users-profile-in-aspnet.html

I have tested it  above link ,it worked on my side

Hope this can be helpful.

Best Regards,

Eileen

Leave a Reply