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 8651999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:12:18+00:00 2026-06-12T14:12:18+00:00

I have a routine that returns mostly correct data. I pass it a string

  • 0

I have a routine that returns mostly correct data. I pass it a string Id code, it creates a model, gets data from a database, fills in the model, and then passes the model back. The return model looks correct and has correct data except the List’s in the model do not contain any data.

The model looks similar to this one

             public class SubjectDB
             {
                public string SubjectId  { get; set; }
                .
                .
                List<AddressDB> Address { get; set; }
                .
                .
                [Key]
                public int Id { get; set; }
             }
             public class DBEntities: DbContent
             {
                public DbSet<SubjectDB> SubjectDB { get; set; }
                public DbSet<AddressDB> AddressDB { get; set; }
                .
                .
             }

The subroutine is called using this code

             SubjectDB xsubject = new SubjectDB();
             xsubject = (SubjectDB)GetNewSubject(model.Subject.Id);

The subroutine is

             Public object GetNewSubject( string Id )
             {

                 SubjectDB subjectdb = new SubjectDB();
                 DBEntites db = new DBEntities();

                 var subjectxx = db.SubjectDB.First(x => x.SubjectId == Id);
                 var addressxx = db.AddressDB.First(x => x.SubjectId == Id);
                 .
                 .
                 subjectdb.SubjectId = subjectxx.Subjectid;
                 .
                 .
                 List<AddressDB> Address = new List<AddressDB>();
                 Address.Add(addressxx);
                 .
                 .
                 return(subjectdb);
              }

I can mouse over the subjectdb in the subroutine and see all the data including the data in the List’s, but when I mouse over the returned object “xsubject”, I see all the correct returned data but the List’s are empty.

  • 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-12T14:12:20+00:00Added an answer on June 12, 2026 at 2:12 pm

    Found the missing piece of the puzzel. I was not initializing the Lists even if they are public.

    Model modified to:

                  public class SubjectDB   
         {   
            public string SubjectId  { get; set; }   
            .   
            .   
            public List<AddressDB> Address { get; set; }   
            .   
            .   
            [Key]   
            public int Id { get; set; }
    
            public SubjectDB()
            {
               this.Address = new List<AddressDB>();
               .
               .
            }   
         }   
         public class DBEntities: DbContent   
         {   
            public DbSet<SubjectDB> SubjectDB { get; set; }   
            public DbSet<AddressDB> AddressDB { get; set; }   
            .   
            .   
         } 
    

    Now it all works. the DbSet commands get the data from the database and the LIST get updated correctly and when the model is passed back to the main, all the data is there.

    Thanks to all that helped me see where I had gone wrong.

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

Sidebar

Related Questions

I have some python code that: Takes a BLOB from a database which is
I'm developing an MVC application and I have a routine that gets the currently
I have a bunch of code in a routine that looks a bit like
I have a fast bit-level routine that calculates a value, and returns a UInt32.
I have a library that exports an unmanaged C routine that returns pointers to
I have this routine that works well, but it messes up as it counts
I have a routine that examines thousands of records looking for discrepancies. This can
I have a routine that dynamically changes a select list's selected option when the
I have a jquery routine that calls an MVC action which will do a
Good Day, I have a simple working routine in Perl that swaps two words:

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.