views:

48

answers:

2

I'm writing a forum in ASP.NET. I have a table of posts. How can I assign a post to a user? If I had a normal User table, I'd just creating a new field in the post table "UserId" and creating an assocation in the Linq to Sql designer. But now? Should I include the aspnet_Users in the designer?

Thanks.

A: 

Write your own ASP.NET Membership provider that uses your own database table and spare yourself the hassle of finding out how the MS lays out it's db tables.

I wrote a blog about that some years ago I think: http://www.tigraine.at/2008/07/08/custom-aspnet-membership-provider/

Hope this helps.

Tigraine
sorry - this is just bad advice.
Sky Sanders
I don't see why. You don't need to implement the whole Membership Provider but only the methods relevant to you (namely: login, forgot password and create user) while you are in complete control of the table you are working against. Doing weak references into built-in tables without L2S designer support is equally bad advice
Tigraine
The ASP.NET membership stuff especially falls apart once you have to add per-data permissions at some stage.
Tigraine
+2  A: 

Including the table in your designer should not be necessary.

Simply define the UserId field in your Posts table as uniqueidentifier and supply the UserId when running your queries.

You can get the Guid (uniqueidentifier) UserId like this:

Guid UserId = (Guid) Membership.GetUser().ProviderUserKey;

There is absolutely no need to implement custom providers to facilitate this requirement.

Sky Sanders