简体   繁体   English

添加迁移未从 MVC 核心中的模型生成 EF 脚本

[英]Add-Migration not generating EF script from model in MVC Core

I am using ASP.Net MVC Core 3 with Entity Framework and SQL Server.我将 ASP.Net MVC Core 3 与 Entity Framework 和 SQL Server 一起使用。 I have been building the supporting database in Azure using Add-Migration and Update-Database in VS 2019 Package Manager Console.我一直在使用 VS 2019 包管理器控制台中的 Add-Migration 和 Update-Database 在 Azure 中构建支持数据库。 I have several model classes that have been used successfully to generate the migration code.我有几个模型类已成功用于生成迁移代码。 However, I have a model from which are generated empty Up() and Down() methods in the migration class.但是,我有一个模型,从中生成了迁移类中的空 Up() 和 Down() 方法。 The model is public, and all of its member properties are public.该模型是公开的,其所有成员属性都是公开的。 I'm really baffled as to what could be happening.我真的很困惑会发生什么。

Here's the model:这是模型:

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace MapItGo_Web_App.Models {
    public class ShippingRequestModel {

        public long ShippingRequestModelID { get; set; }

        [Required(ErrorMessage = "Please enter your First Name")]
        [StringLength(100)]
        [DataType(DataType.Text)]
        public String FirstName { get; set; }

        [Required(ErrorMessage = "Please enter your Last Name")]
        [StringLength(100)]
        [DataType(DataType.Text)]
        public String LastName { get; set; }

        [Required(ErrorMessage = "Please enter your Email Address")]
        [StringLength(100)]
        [DataType(DataType.EmailAddress)]
        public String Email { get; set; }

        [Required(ErrorMessage = "Please enter your Phone Number")]
        [StringLength(100)]
        [DataType(DataType.PhoneNumber)]
        public string PhoneNumber {get; set;}

        [StringLength(2500)]
        [DataType(DataType.MultilineText)]
        public string Comments { get; set; }
    }
}

Any help would be greatly appreciated.任何帮助将不胜感激。

As @ShawnOrr points out below, I needed to add the DbSet for ShippingRequestModel to my DbContext class.正如@ShawnOrr 在下面指出的那样,我需要将 ShippingRequestModel 的 DbSet 添加到我的 DbContext 类中。 That did the trick.这就是诀窍。

        public DbSet<ShippingRequestModel> ShippingRequests { get; set; }

Thanks, Shawn!谢谢,肖恩!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM