Hassan
Hassan

Reputation: 1433

Asp.net MVC + Membership + Code-First + Existing Database

After lot of research and attempts I failed, here is the situation :

Technologies

I used Code First to create my domain classes, example :

public class Country{
   public int IdCountry {get;set;}
   public int NameCountry {get;set;}
}
public class Sex{
   public int IdSex {get;set;}
   public int NameSex{get;set;}
}

etc... I have like 20 classes

All I want is :

Use the Asp.Net Membership system, and plug it to my classes. I have a domain class called UserProfile

public class UserProfile{
   public int IdUserProfile {get;set;}
   public virtual Sex sex {get;set;}
   public virtual Country country {get;set;}
   public virtual ICollection<Photos> photos {get;set;}
   etc...
}

I want to be able to connect all this with the Asp.Net User registered via Asp.Net Membership and the AccountController

I search in stackoverflow, codeplex etc.. and I dont find a solution for that or perhaps I did not understand.

I hope someone have achieved this in real world application :)

ps : I am working on a "dating" Website

Upvotes: 2

Views: 937

Answers (1)

OdeToCode
OdeToCode

Reputation: 4986

The AccountController in MVC 4 already relies on SimepleMembership and other WebMatrix bits to support membership with both OAuth and local accounts.

My suggestion would be to start by removing the DbContext derived class defined in the AccountModel.cs for your MVC 4 project and replacing it with your own (the compiler errors will tell you what you have to change once you remove the class).

I'd also remove the SimpleMembershipInitializerAttribute from the project and make sure to perform the initialization tasks during Application_Start instead. The filter has a few subtle flaws. When I get a chance to post about this, I'll update this with a URL.

Upvotes: 3

Related Questions