Question

First I am really new to .NET framework and all stuff around. What I want to do is to build my admin part for my n-tiers MVC4 App where security is dealt with SimpleMembership. (the default)

Regarding the standard MVC4 template and in order to create my GetAllUsers method, I have decided to create my membership entities (UserProfile, Membership, OAuthMembership and Roles) in my domain project with EF reverse engineer code first tool and generating my context and my repositories with T4 template for my DAL project.

I am surprised that the Membership Table is not linked with the UserProfile (as you can see in the schema) and I would be really pleased to know why (? first question)

membership_schema

In a console "test" app, (the final goal is to create a gridview where I can have Membership Table and UserProfile Table Infos linked together) there is the method I create in order to get shared Membership and UserProfile info for my users (my service project is not set yet).

Is this the correct way to do it? (second question)

    private static void GetAllUsers()
    {
        using (var MembershipRepository = new MembershipRepository())
        {
            var i = 1;
            foreach (var member in MembershipRepository.All)
            {
                Console.Write("{0}: {1} ", i, member.UserId);
                using (var UserProfileRepository = new UserProfileRepository())
                {
                    Console.WriteLine("{0}", UserProfileRepository.Find(member.UserId).UserName);
                }
                i += 1;
            }
        }
        WaitConsole();
    }

(note: I didn't use UnitOfWork and IoC yet but I plan to do it)

Thanks a lot to know if I am on the right track.

Was it helpful?

Solution

I really suggest that you don't use the default membership schema. It's poorly designed and you don't need most of the data in there. Rather make your own DB and define your own Membership and Role providers as it seems fit to you.

Have a look at my previous answer: https://stackoverflow.com/a/10067020/1241400

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top