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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:44:35+00:00 2026-06-14T07:44:35+00:00

I perform the following for each loop to insert models into a list: Dim

  • 0

I perform the following for each loop to insert models into a list:

        Dim weights = weight.Where(Function(x) x.FW_Food_ID = item.NDB_No)

        For Each i In weights
            Dim model = New Tbl_Food_Weight
            model.FW_GmWt = i.FW_GmWt
            Debug.Print("i.FW_GmWt=" + i.FW_GmWt)
            Debug.Print("model.FW_GmWt=" + model.FW_GmWt)
            model.FW_Food_ID = i.FW_Food_ID
            Debug.Print("i.FW_Food_ID=" + i.FW_Food_ID)
            Debug.Print("model.FW_Food_ID=" + model.FW_Food_ID)
            model.FW_Option = i.FW_Option
            Debug.Print("i.FW_Option=" + i.FW_Option)
            Debug.Print("model.FW_Option=" + model.FW_Option)
            model.FW_ID = i.FW_ID
            Debug.Print("i.FW_ID=" + i.FW_ID.ToString)
            Debug.Print("model.FW_ID=" + model.FW_ID.ToString)
            item.test.Add(model)
        Next

My model is as follows:

Public Class Tbl_Food_Weight

    <Key()> _
    Public Property FW_ID As Integer
    Public Property FW_Food_ID As String
    Public Property FW_Option As String
    Public Property FW_Serving_Size As String
    Public Property FW_GmWt As String

End Class

My test property is as follows:

<NotMapped()> _
Public Overridable Property test As List(Of Tbl_Food_Weight)

The output that I get is:

i.FW_GmWt=250
model.FW_GmWt=250
i.FW_Food_ID=12695
model.FW_Food_ID=12695
i.FW_Option=1
model.FW_Option=1
i.FW_ID=4481
model.FW_ID=4481
A first chance exception of type 'System.NullReferenceException' occurred in MyBlog.DLL

The error occurs on this line:

item.test.Add(model)

You see, it puts in the variables, but when I go to add the model to the list, it says it’s null. How can I add the model to the list of models?

Thank you.

Edit:

Item in context:

For Each item In food

            Dim weights = weight.Where(Function(x) x.FW_Food_ID = item.NDB_No)
            ... rest of code already posted above
  • 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-14T07:44:36+00:00Added an answer on June 14, 2026 at 7:44 am

    model isn’t null — your test property is. In the constructor of whatever item is, you need to “new” your collection.

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

Sidebar

Related Questions

I need a VBA function that will perform the following: Find all unique values
I have the following code: var posts = elementToAdd.find(.post); posts.each(function(i, e) { var elementHeight
When I perform the following: $popular_posts = $this->Blog->find('all', array('limit' => 5)); I get the
We need to perform the following operation in our database : There is a
If I perform the following query in MongoDB shell, all is fine: db.users.find({location: {$near:
What I need - The code to perform the following: I am trying to
I need a query to perform the following: find the countryID where country =
Which is the best way to perform the following: Lets say i have a
I am trying to determine the correct RegEx syntax to perform the following. I
Using the JavaScript Native Interface of GWT I can perform the following: public native

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.