简体   繁体   English

实体框架4.1无效的对象名称“ us”

[英]Entity Framework 4.1 Invalid object name 'us'

i've used ef power tools to reverse engineer a database. 我使用过ef电动工具对数据库进行反向工程。 it created the classes and mapping using code first. 它首先使用代码创建了类和映射。 not a problem there. 那里不是问题。

but when i try to run the following code: 但是当我尝试运行以下代码时:

using (var tmp= new PdbContext("nameofdb")
                {


                    try
                    {
                        tmp.Configuration.AutoDetectChangesEnabled = false;


                        var tmpUsr = (from t in tmp.DadosUtilizadores
                                      where t.inactivo == false
                                      select t).ToList();
                    }
                    finally
                    {
                        tmp.Configuration.AutoDetectChangesEnabled = true;
                    }
                }

it throws an exception with the following text. 它会引发带有以下文本的异常。

Invalid object name 'us' 无效的对象名称“ us”

i've searched around here and found out that by doing the following would solve my problem: 我在这里搜索,发现通过执行以下操作可以解决我的问题:

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

but it still doesn't resolve my problem. 但这仍然不能解决我的问题。 so i checked the name of the table, and it's correct. 所以我检查了表的名称,这是正确的。 opened linqpad and tried to acess the data and it worked without any issues. 打开linqpad并尝试访问数据,它可以正常工作。 one thing caught my eye. 一件事引起了我的注意。 the table has a trigger, will the trigger raise issues on this situation? 该表有一个触发器,触发器会在这种情况下引发问题吗?

for better understanding the following code refers to my context class named PdbContext and the mapping class named UtilizadoresMap. 为了更好地理解,以下代码引用了我的上下文类PdbContext和映射类UtilizadoresMap。

PdbContext class PdbContext类

public class PdbContext:DbContext
    {
        public DbSet<Fltcl> FiltrosClientes { get; set; }
        public DbSet<Fltst> FiltrosStocks { get; set; }
        public DbSet<Bo> DossiersInternos { get; set; }
        public DbSet<Cl> DadosClientes { get; set; }
        public DbSet<Utilizadores> DadosUtilizadores { get; set; }

        public PdbContext(string valueConn):base(valueConn)
        {
            Database.SetInitializer<PdbContext>(null);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new FltstMap());
            modelBuilder.Configurations.Add(new FltclMap());
            //modelBuilder.Configurations.Add(new ClMap());
            modelBuilder.Configurations.Add(new UtilizadoresMap());

            //teste
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            //
            base.OnModelCreating(modelBuilder);
        }
    }

UtilizadoresMap class UtilizadoresMap类

public class UtilizadoresMap : EntityTypeConfiguration<Utilizadores>
    {
        public UtilizadoresMap()
        {
         .......
         ToTable("us");
        }
     }

help would be appreciated thanks in advance 帮助将不胜感激在此先感谢

finally i've figured it out. 终于我明白了。 the problem was that i using a providerconnectionstring to a database instead of loading only the string and let entity framework create it. 问题是我使用providerconnectionstring到数据库,而不是仅加载字符串并让实体框架创建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM