?
Solved

Include Login UserID with Linq to sql

Posted on 2010-09-13
1
Medium Priority
?
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

649 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