2

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.

12
  • 1
    Try ProjectUsers instead of ProjectUser Commented Mar 31, 2019 at 7:51
  • could you please add the context you are trying to use .do you have a property of DbSet<ProjectUser> ProjectUser{get;set;} Commented Mar 31, 2019 at 7:54
  • doesn't contain definition for ProjectUsers Commented Mar 31, 2019 at 7:54
  • public virtual DbSet<ProjectUser> ProjectUser { get; set; } Commented Mar 31, 2019 at 7:55
  • 1
    Probably the error just raised from DataAnnotations settings in User or Project models Commented Mar 31, 2019 at 11:53

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.