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

  • Home
  • SEARCH
  • 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 9151785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:53:14+00:00 2026-06-17T11:53:14+00:00

I am new to the entity framework, and C# but not SQL. I have

  • 0

I am new to the entity framework, and C# but not SQL. I have table [Contact] with multiple fields referencing a lookup table called [XRef_Codes]. First, I want to bind all dropdownlists on an asp.net webform to the filtered lookup table on page load. Second, I want to be able to expose the lookup values (integers and text value) in the contact entity model (see below)

Here is a sample of fields in the
[Contact] table:
FirstName (vchar(50)
LastName (vchar(50)
xPrefix (int)
xSuffix (int)
xReferral (int)
xStatus (int)
xGender (int)
xMaritalStatus (int)
xAgeGroup (int)

I have a self-referencing lookup table called [xRef_Codes] that has the pick values for all the fields prefixed “x” in the contact table (i.e. xPrefix, xSuffix):
[xRef_Codes]
CodeID (int)
CodeName (vchar50)
OfCodeID (int)
SortOrder (int)
SetAsDefault (bit)

[1] In my asp.net form, I want to populate a sorted/filtered dropdownlists FROM xRef_Codes table WHERE OfCodeID=## ORDER BY SetAsDefault, SortOrder. In the page load, I would bind all of the dropdownlists at one time.

[2] I want to associate the related XRef_Codes “CodeName” value as part of the contact object/entity. So I could see that contact.prefix.CodeName =”Mr.” and contact.suffix.CodeName = “Sr.” and contact.gender.CodeName =”Male”, etc.

What is the best approach to this? Can some help me understand if I need to correlate all these fields in the entity framework designer?

  • 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. Editorial Team
    Editorial Team
    2026-06-17T11:53:15+00:00Added an answer on June 17, 2026 at 11:53 am

    I am new to things, so I thought I would share the fruits of my journey. My solution was to utilize the global.asax file, and the Session_Start() object.

    First, I created a class for my dropdown list codes called xRefCodesRepository. In my first routine I load the values into a session variable like this:

     public void xref_LoadIntoSessionCache()
             {
                 MyDatabaseEntities ctb = new MyDatabaseEntities();
                 List<XRef_Codes> allCodes = (from x in ctb.XRef_Codes
                            orderby x.OfCodeID, x.SetAsDefault descending, x.SortOrder
                            where (x.IsImplemented == true)
                            select x).ToList();
                 HttpContext.Current.Session["ListOfCodes"] = allCodes;
             }
    

    Second, I add a class routine to fetch my codes by a parentID value. In my case, I have a self-referencing table with fields like CodeID, CodeName, OfCodeID, etc. I fetch my codes like this:

    public List<XRef_Codes> xref_GetChildCodes(Int32 OfCodeId)
            {
                //List<XRef_Codes> allCodes = (List<XRef_Codes>)Session["ListOfCodes"];
                List<XRef_Codes> xCodes = xref_GetAllCodes();
                xCodes = (from x in xCodes
                          orderby x.OfCodeID, x.SetAsDefault descending, x.SortOrder
                          where x.OfCodeID == OfCodeId
                          select x).ToList();
                return (xCodes);
            }
    

    Next, I edit my global.asax file. I reference my class folder i.e. using MyDatabase.CLASSNAME;
    Then I add a routine in my global.asax that calls the class routine that loads the codes into a session variable:

    void Session_Start(object sender, EventArgs e)
            {
                // Code that runs when a new session is started
                xRefCodesRepository x = new xRefCodesRepository();            
                x.xref_LoadIntoSessionCache();
            }
    

    Finally, in my code I reference the session cache to populate various objects.

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

Sidebar

Related Questions

When adding a new Entity Framework object to a database, how could one have
I'm new to Entity Framework and am using Database First. I have inherited a
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I am new to working with the Entity Framework with SQL Server and I
I have an entity framework (3.5) data model pointing to a remote SQL Server
I have 4 tables: but when I create an entity framework model, why is
I am new the code-first Entity Framework. I have tried a few things now,
For simplicity's sake, let's say I have a SQL Server CE table called Widgets
I heard about the new entity framework for .net, and decided to modify my
I just downloaded and installed the brand new Entity Framework 5.0 beta 2 which

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.