Solved

Include Login UserID with Linq to sql

Posted on 2010-09-13
1
428 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now