user1668543
user1668543

Reputation: 309

Error comes as a {"Invalid object name 'dbo.TableName'."}

I'm using Entity Framework and MVC3, I have used Model First approch... I have used Company as a Base class and I have inherited the Lead Class from it.

When I run the application its gives an error...

This is Base Class

using System;
using System.Collections.Generic;

    namespace CRMEntities
    {
        public partial class Company
        {
            public int Id { get; set; }
        }

    }

This is Lead Class (Child)

using System;
using System.Collections.Generic;

namespace CRMEntities
{
    public partial class Lead : Company
    {
        public Lead()
        {
            this.Status = 1;
            this.IsQualified = false;

        }

        public Nullable<short> Status { get; set; }
        public Nullable<bool> IsQualified { get; set; }


    }


}

I have added the controller,and in index view I have added this code...

public class Default1Controller : Controller
    {
        private CRMWebContainer db = new CRMWebContainer();

        //
        // GET: /Default1/

        public ViewResult Index()
        {

            return View(db.Companies.OfType<Lead>().ToList());
         } 
    }

This is DB and Model ...

enter image description here

Its giving the inner error -

{"An error occurred while executing the command definition. See the inner exception for details."} {"Invalid object name 'dbo.Companies'."}

Upvotes: 0

Views: 5531

Answers (1)

kevin_fitz
kevin_fitz

Reputation: 857

Do you have a Companies table or Company table in your database. It looks like you have a Mapping issue. Entity Framework will make some guesses as to how it pluralizes entity names by default.

Upvotes: 2

Related Questions