views:

155

answers:

2

At the table level I'm setting aspnet_User.UserID as foreign key of UserID in the other tables (like Posts.UserID, so each post has an owner). Is that the way to go?

When I create the LINQ to SQL model, should I include the aspnet_User table?

When I create a post (record in the Posts table, a Post object), how do I set the relationship to the logged in user (User object in the controller)?

+1  A: 

I don't include the aspnet_User table to my linq-to-sql as I don't really need it. I use the built in way of accessing membership data.

But for your table Posts, it might be easier for you to include it so that you can easily display the User's Name by doing myPost.User.Name

edit:

    MembershipUser user = Membership.GetUser();
    Guid userGuid = (Guid)user.ProviderUserKey;

    Post post = new Post
            {
                 UserId =userGuid,
                 Message = message                                      
            };
Thomas Stock
How do I add user to a post?
J. Pablo Fernández
updated my reply
Thomas Stock
A: 

In your database schema, you should definately have a the UserID in the Post table be a foreign key to the aspnet_user table, on the UserID field. This way, you are making sure your data is clean. I would even add a cascade delete & update on that relationship.

Then, refer to my instructions in a previous question you asked, about how to get the user data.

(Thomas Stock summed it up briefly, above, though :) )

Pure.Krome
So, the User object that Asp.NET MVC provides is useless?
J. Pablo Fernández

related questions