Solved

Include Login UserID with Linq to sql

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data is not showing from images 15 38
Remove greater than sign 3 49
Help with Syntax 9 29
Get size of each directory on each mapped drive 5 24
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

23 Experts available now in Live!

Get 1:1 Help Now