Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 170115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:45:03+00:00 2026-05-11T12:45:03+00:00

I’m using Linq2SQL and I’m pretty new to it. I’ve got a User table

  • 0

I’m using Linq2SQL and I’m pretty new to it.

I’ve got a User table and a UserData table, the idea being that properties for the User object can be added / removed by adding or removing rows in the UserData table. I did not come up with this particular design but I am more or less stuck with it (as long as I can come up with a solution)

alt text http://www.86th.org/linq2sqlproblem.jpg

I’d like to populate/bind ‘FirstName’ on the User object by something along the lines of setting the value to:

 UserData.Value WHERE UserData.ItemID == User.UserID AND KeyName = 'FirstName' 

Similarly, LastName would be:

 UserData.Value WHERE UserData.ItemID == User.UserID AND KeyName = 'LastName' 

Description of the UserData Table:

  • UserData.ItemID is the FK (User.UserID)
  • UserData.KeyName is specifying the name of the property
  • UserData.Value is the actual value.

How would I setup my User object to handle this so I could do the normal CRUD functionality on this object and have the changes carry through to both tables?

Is this even possible?

Is this bad form?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:45:04+00:00Added an answer on May 11, 2026 at 12:45 pm

    Quick Note

    I renamed UserData to ExtendedProperty and this caused the relationship from User to ExtendedProperty to be called ExtendedProperties.

    Summary of changes

    1. Created a getter/setter for both FirstName and LastName in the partial User class
    2. Grabbed the correct ExtendedProperty element out of the ExtendedProperties collection and either returned or updated the Value property of it.
    3. Refactored into a reusable format as shown below
     partial class User {     public string FirstName     {         get { return (string)this.getExtendedProperty('FirstName').Value; }         set { this.getExtendedProperty('FirstName').Value = value; }     }      public string LastName     {         get { return (string)this.getExtendedProperty('LastName').Value; }         set { this.getExtendedProperty('LastName').Value = value; }     }      // Grab a related property out of the collection, any changes to it will be reflected in the database after a submit     private ExtendedProperty getExtendedProperty(string KeyName)     {         // grab the properties that fit the criterea         var properties = (from prop in this.ExtendedProperties where prop.KeyName == KeyName select prop);          // return value         ExtendedProperty property = properties.SingleOrDefault();          // if this is a new user then there arent going to be any properties that match         if (property == null)         {             // Define a new item to add to the collection             property = new ExtendedProperty()             {                 ItemID = this.UserID,                 KeyName = KeyName,                 Value = String.Empty             };              // Add the item we're about to return to the collection             this.ExtendedProperties.Add(property);         }          // either way we have a valid property to return at this point         return property;     } }  

    I just hope this isn’t bloated / grossly inefficient.

    Edit

    In getExtendedProperty, it would error when setting the FirstName or LastName of a newly created User because it would not have any corresponding ExtendedProperty elements in the ExtendedProperties collection as shown below.

    User expected = new User(); expected.UserID = Guid.NewGuid(); expected.UserName = 'LJ'; expected.FirstName = 'Leeroy';  // It would error here expected.LastName = 'Jenkins'; 

    Because of this I added a check to ensure that new items get added to the ExtendedProperties collection if they are requested and not currently in there.

    I also removed setExtendedProperty since I felt it wasn’t necessary and was just a method around a 1 liner anyway.

    I would really appreciate any feedback before I accept this answer, I’ll let it sit for a few days.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 87k
  • Answers 87k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer C# 3 has a language extension called collection initializers which… May 11, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer I've been working on line of business .NET apps for… May 11, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer I'll preface this by saying I use Blogger not Wordpress… May 11, 2026 at 5:32 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.