错误来自{“无效的对象名称”dbo.TableName“。”} [英] Error comes as a {"Invalid object name 'dbo.TableName'."}

查看:204
本文介绍了错误来自{“无效的对象名称”dbo.TableName“。”}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Entity Framework和MVC3,
我已经使用Model First Appro ... ...
我已经使用了公司作为Base类,我已经继承了 Lead 类。



当我运行应用程序时,它发出错误...



这是基类

  using System; 
使用System.Collections.Generic;

命名空间CRMEntities
{
public partial class Company
{
public int Id {get;组; }
}

}

这是铅班)

  using System; 
使用System.Collections.Generic;

命名空间CRMEntities
{
public partial class Lead:Company
{
public Lead()
{
this.Status = 1;
this.IsQualified = false;

}

public Nullable< short>状态{get;组; }
public Nullable< bool>已获得组; }


}


}

我添加了控制器,在索引视图中我添加了这个代码...

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

//
// GET:/ Default1 /

public ViewResult Index()
{

return View db.Companies.OfType<铅及GT;()ToList());
}
}

这是DB和Model ...





它给出内部错误 -


{执行命令定义时发生错误。 $ b内部异常的详细信息。} {无效的对象名称
'dbo.Companies'。}



解决方案

您的数据库中有公司表还是公司表。看起来你有一个Mapping问题。默认情况下,实体框架将会对实体名称进行多元化的猜测。


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 ...

Its giving the inner error -

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

解决方案

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.

这篇关于错误来自{“无效的对象名称”dbo.TableName“。”}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆