Invalid object name 'dbo.TableName' when retrieving data from generated table

前端 未结 5 1264
感情败类
感情败类 2021-01-19 07:23

I\'m using entity framework code first to create my tables. Please note - create the tables, not the DB, since I\'m working on a hosted environment and I don\'t have a user

5条回答
  •  囚心锁ツ
    2021-01-19 08:20

    Ok, for me issue was that I had a table called dbo.UserState and in C# EF was trying to access dbo.UserStates because of pluralization.

    The solution was to put Table attribute above class and specify the exact table name:

    [Table("UserState")]
    public class UserState
    {
        [Key]
        public int UserId { get; set; }
    }
    

提交回复
热议问题