SqlException (0x80131904): Invalid object name 'dbo.Categories'

后端 未结 5 582
我寻月下人不归
我寻月下人不归 2020-12-03 07:47

I am getting the exception above when I run an application. The application is using asp.net mvc 3 / C#. I made an mdf file and added it under App_Data folder in Visual Web

5条回答
  •  执念已碎
    2020-12-03 08:42

    Since this was still top search hit on the exception in April of 2018 and it led me to a solution, let me tack this on for a specific situation...

    Our application is based on ABP and ABP.Zero, and we already have a pattern that fit Marc's answer. While I bet explicit mapping in the OnModelCreating method (a la Dhananjay's answer) would have worked perfectly, it seemed like ABP's mapping was working perfectly up to this point and I didn't want to break the pattern.

    My solution was to add a table attribute to the entity class, and this settled EF's confusion.

    using System;
    using Abp.Domain.Entities;
    using System.ComponentModel.DataAnnotations.Schema;
    
    namespace Discovery.History
    {
    
        [Table("HistoryRecords")]
        public class HistoryRecord : Entity
        {
            public int ResearcherCount { get; set; }
            public DateTime DateSubmitted { get; set; }
            public string Comments { get; set; }
        }
    }
    

提交回复
热议问题