Solved

Include Login UserID with Linq to sql

Posted on 2010-09-13
1
431 Views
Last Modified: 2013-11-11
Hi EE,

I have an app that uses the membership provider.  
I designed my sql server 2005 tables with the foreign key UserID uniqueidentifier.
I want to use Linq to sql to bind my forms, fields, etc. and was wondering what would be the best way to do this, when I have to include the UserID in all my inserts/updates.
Please provide an example.
Thank you
0
Comment
Question by:Sheritlw
1 Comment
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 33679764
Hi,

You could do something simple like:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            If User.Identity.IsAuthenticated Then
                Dim u As MembershipUser = Membership.GetUser(User.Identity.Name.ToString())
                Session("UserID") = u.ProviderUserKey.ToString()
            End If
        End If

        Dim dc As New MyLinqClassesDataContext()
        Dim q = From a As MyData In dc.GetTable(Of MyData)() Where a.UserID = Session("UserID")

    End Sub

Hope this helps!

/Carl.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question