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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:14:37+00:00 2026-06-07T08:14:37+00:00

I’m creating an expense report project – my first using MVC. This is a

  • 0

I’m creating an expense report project – my first using MVC.

This is a Database First project and I’m using Oracle ODP.

I have an entity model with the following classes:
ExpenseReport
ExpenseItem
ExpenseType

The expense report will have many expense items.
Each expense item will be of a specific expense type from the list of types in that ExpenseType class – thus a many-to-one relationship.

A single expense type record contains for each type a category, and headings for description/comment field to go with that type.

In my view, I am able to display the report with a list of all the expense items for that report. I am doing this through my Edit or Details controllers with the following code:

public ActionResult Details(long id)
{
   using (var db = new Entities())
   {
      var thisReport = db.ExpenseReport.Find(id);
      thisReport.expItems = db.ExpenseItem.Where(e => e.BB_EXPREPORT_ID == id).ToList();
      return View(thisReport);
   }
}

I tried adding this to the code (just above the return View line) to also include the expense type values (category, headings) for each type but it is failing due to a casting issue – cannot implicitly convert (are you missing a cast?)

foreach (ExpenseItem item in thisReport.expItems)
{
  item.expType = db.ExpenseType.Where(e => e.BB_EXP_TYPE == item.BB_EXP_TYPE);
}

My questions:

  1. Isn’t there a way I can set up my model classes so that I don’t need
    to add these statements? I.E. Can’t I modify the virtual object Get
    statement to pull them there? Or can I modify the entitymodel file
    to get these values? Is it a loading issue? I turned off lazy
    loading.
  2. If there is not a way to do this at the model level so that virtual
    objects are included in the get, then how can I set the cast in my
    code above to pull the values from the ExpenseType table for that
    given expense type?

Thanks.

  • 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-07T08:14:39+00:00Added an answer on June 7, 2026 at 8:14 am

    Admittedly, I’m not sure of what you’re trying to do, but it looks like you just want to load up your object all at once. You can do this with Entity Framework using the Include method.

    I’d assume you’re using the “pluralization” feature for naming your db sets, but then again, your call to “db.ExpenseReport” is missing an (s) at the end.

    public ActionResult Details(long id) {
     using (var db = new Entities()) {
      ExpenseReport thisReport = db.ExpenseReport.Include("ExpenseItems.ExpenseType").Single(id);
    
      return View(thisReport);
     }
    }
    

    Then you can use it in your Razor view like so.

    <ul>
     foreach (var item in Model.ExpenseItems) {
      <li>Name: @item.YourExpenseItemName - Type: @item.ExpenseType.YourTypeName</li>
     }
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I'm making a simple page using Google Maps API 3. My first. One marker

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.