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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:23:11+00:00 2026-05-26T05:23:11+00:00

I have setup EF code first against my DB (specifically, a table called tblExpenseMain).

  • 0

I have setup EF code first against my DB (specifically, a table called tblExpenseMain).

In my controller I’m trying to pass an instance of my ‘ExpenseMain’ class over to the view so the details can be presented. Manually creating an instance and passing it works:

ExpenseMain em = new ExpenseMain { Card_Number = "123", UniqueID_ERLineID = "blah", Item_Amount = 500, Item_Expense_Type = "something"};

            return View("_Basic");

But trying to query it with LINQ like so gives me an exception:

ExpenseMain model = (from e in db.ExpenseMains
                                 where e.UniqueID_ERLineID == transUniqueID
                                 select e).SingleOrDefault();

It tells me to check the innerexception to find the problem. I surrounded it with a try/catch and the innerexception message was:

e.InnerException.Message = “Invalid object name ‘dbo.ExpenseMains’.”

Any suggestions on what I’m doing wrong? I was hoping that the linq query would just grab my single instance and go from there. Changing ‘Expensemain model’ to ‘var model’ and looking at what the var becomes, confirms it becomes an ‘Expensemain’ anyway.

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-05-26T05:23:12+00:00Added an answer on May 26, 2026 at 5:23 am

    If your class name is different from the table name, then you have to configure EF to map them. You can use the table attribute and give the table name.

    [Table("tblExpenseMain")]
    public class ExpenseMain
    {
        //properties
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to setup a few fixes in some code that have caught
Setup Using MVC 3 + Code First Here are my classes public class Member
I am using EF4 CPT4 Code first and I have setup my ObjectContext to
I have setup a simple test project for the EF 4.1 RC, using Code-First
Trying to do some unit testing with EF 4.1 code first. I have my
I have some setup code in my functions.php file that sets permalinks and adds
I have the following setup: Code on my local machine (OS X) shared as
We have a setup where most code, before being promoted to full production, is
Setup Have you ever had the experience of going into a piece of code
I have the following piece of code: // setup the AJAX request var pageRequest

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.