Invalid column name Entity Framework Core

c# entity-framework-core

Question

I have following entity class:

public partial class ProjectUser
{
        public int Id { get; set; }
        public int ProjectId { get; set; }
        public int UserId { get; set; }

        public virtual Project Project { get; set; }
        public virtual Users User { get; set; }
}

When I perform the following:

myDbContext.ProjectUser.ToList()

I get this error:

System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'ProjectUser'

My dbcontext has the following property:

public virtual DbSet<ProjectUser> ProjectUser { get; set; }

Table script is as following.

CREATE TABLE [dbo].[ProjectUser]
(
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ProjectId] [int] NOT NULL,
    [UserId] [int] NOT NULL,

    CONSTRAINT [PK_ProjectUser] 
        PRIMARY KEY CLUSTERED ([Id] ASC)
                    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
                          IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                          ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

What's wrong? Class has been generated with scaffolding.

1
1
3/31/2019 11:39:05 AM

Accepted Answer

Probably the error just raised from DataAnnotation naming settings in User or Project models.

1
3/31/2019 3:10:05 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow