Solved

Include Login UserID with Linq to sql

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

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 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