Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Entity Framework – Microsoft.Data.SqlClient.SqlException: 'Invalid object name

I have manually mapped a pre-existing table to a model and dbcontext

enter image description here

namespace App.Monitoring.DbContext
{
    using Microsoft.EntityFrameworkCore;
    using App.Monitoring.DbContext.Models;

    public partial class Context: DbContext
    {
        public virtual DbSet<tDataLoad> tDataLoad { get; set; }

        public Context(DbContextOptions<Context> options) : 
        base(options)
        {

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<tDataLoad>(entity =>
            {
                entity.HasIndex(e => new { e.DataLoad_Id})
                    .IsUnique();

                entity.Property(e => e.DataLoad_Id)
                    .IsRequired()
                    .HasMaxLength(255);  

            });
       }
    }
}

But when I’m trying to access table

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    _dataContext.tDataLoad.ToList();

I keep getting

enter image description here

>Solution :

You are likely missing the schema specification in your mapping. Please use the following for proper configuration.

entity.ToTable("tDataLoad", "log");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading