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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:36:39+00:00 2026-05-28T15:36:39+00:00

I am working on a form to add new inventory into an inventory tracking

  • 0

I am working on a form to add new inventory into an inventory tracking database I designed. I have done a mapping to EF and I am using LINQ to EF to query data.

The equipment table has a navigation property EquipmentInventories. Consider the following snippet of code:

public partial class Content_AddInventoryItems : System.Web.UI.Page
{
    public Equipment equipment;

    protected void Page_Load(object sender, EventArgs e)
    {
        using (MSSInvDBEntities myEntities = new MSSInvDBEntities())
        {
            var manuPop = (from equipment in myEntities.Equipments
                           select equipment.equipmentManu).Distinct();
            ManuList.DataSource = manuPop;
            ManuList.DataBind();
        }
        using (MSSInvDBEntities myEntities = new MSSInvDBEntities())
        {
            var modelPop = from equipment in myEntities.Equipments
                           select equipment.equipmentModel;
            ModelList.DataSource = modelPop;
            ModelList.DataBind();
        }

    }

    private void DisplayEquipmentData()
    {
        ManuList.SelectedValue = equipment.equipmentManu;
        ModelList.SelectedValue = equipment.equipmentModel;
        tboSerial.Text = equipment.EquipmentInventories.serialNumber;

    }
}

However I keep getting errors when I try to reference the serialNumber property of the EquipmentInventories object using the EquipmentInventories navigation property of the equipment object.

Any ideas where I went wrong?

  • 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-05-28T15:36:39+00:00Added an answer on May 28, 2026 at 3:36 pm

    I don’t see where you instantiate your public field equipment. (equipment in from equipment in... is another variable, the range variable for the LINQ query.) Looking at your code I’d expect a NullReferenceException because equipment is null.

    You should have something like:

    using (MSSInvDBEntities myEntities = new MSSInvDBEntities())
    {
        equipment = (from e in myEntities.Equipments
                     select e)
                    .FirstOrDefault();
    }
    

    But this would cause an exception as well because you don’t load the equipment.EquipmentInventories property and lazy loading won’t work in your DisplayEquipmentData method because you already have disposed the context (automatically at the end of the using block). Lazy loading requires a context which isn’t disposed yet.

    In your case I would use eager loading though:

    using (MSSInvDBEntities myEntities = new MSSInvDBEntities())
    {
        equipment = (from e in myEntities.Equipments.Include("EquipmentInventories")
                     select e)
                    .FirstOrDefault();
    }
    

    Then the navigation property is loaded at once with this query and you can safely dispose the context.

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

Sidebar

Related Questions

I'm working on a form to add new Customers. In this form the users
I have a form in witch users can add their working hours view them
i generated doctrine-admin in backend. In frontend i have form for add new news.
I have a form that I want to be used to add entries. Once
I have a dialog form. <div id=dialog-form title=Create new Admin> <p class=validateTips>All form fields
I have a working form which sends emails from the default logged in account.
I would like to add new fields at user profile. Its working on admin
I have a Create New Employee ASP.Net MVC form. My complex object is an
I have a working login form. I was just trying to do a simple
I am working on a Windows Form-Based application in Visual Studio 2008 using C#

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.