小编ha3*_*a33的帖子

Add-Migration:找不到与参数名称“Context”匹配的参数

   Add-Migration : A parameter cannot be found that matches parameter name 'Context'.
At line:1 char:15
+ Add-Migration -Context ManagementSystemContext
+               ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-Migration], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Add-Migration
Run Code Online (Sandbox Code Playgroud)

我正在尝试将迁移添加到应用程序,但尽管使用此命令,我还是收到了此错误:

PM> Add-Migration -Context ManagementSystemContext
Run Code Online (Sandbox Code Playgroud)

我卸载了 EntityFrameWork.tools 然后重新安装它并重新启动 Visual Studio,但仍然出现相同的错误

c# asp.net asp.net-mvc asp.net-core

6
推荐指数
2
解决办法
1万
查看次数

参数 1:无法从“System.Collections.Generic.List”转换为“System.Collections.Generic.List”

我正在学习 Asp.net Core 并使用 CRUD 操作、SQL 服务器和使用实体框架构建一个简单的 Web。当我尝试构建排序方法时,我在参数员工的这一行中收到此错误

return View(this.SortEmployees(employees, SortField, CurrentSortField, SortDirection));
Run Code Online (Sandbox Code Playgroud)

这就是错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'System.Collections.Generic.List<EmployeesApp.Models.Employee>' to 'System.Collections.Generic.List<EmployeesApp.Controllers.Employee>' EmployeesApp    
Run Code Online (Sandbox Code Playgroud)

那是我的模型:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace EmployeesApp.Models
{
    [Table("Employee", Schema ="dbo")]

    public class Employee
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Name ="Employee ID")]
        public int EmployeeId { get; set; }


        [Required]
        [Column(TypeName ="varchar(5)")]
        [MaxLength(5)]
        [Display(Name ="Employee Number")]
        public string EmployeeNumber { get; set; }


        [Required]
        [Column(TypeName = "varchar(150)")]
        [MaxLength(100)]
        [Display(Name …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-core

4
推荐指数
1
解决办法
1万
查看次数

Microsoft.EntityFrameworkCore.DbUpdateException:保存实体更改时发生错误。详细信息请参见内部异常

我正在学习 Webapi,所以我尝试构建一个连接到 SQL 服务器的简单 Api,当我添加新的电影数据时出现此错误

Microsoft.EntityFrameworkCore.DbUpdateException:保存实体更改时发生错误。有关详细信息,请参阅内部异常。---> Microsoft.Data.SqlClient.SqlException (0x80131904):INSERT 语句与 FOREIGN KEY 约束“FK_Movies_SuperHeroes_HeroId”冲突。冲突发生在数据库“SupersDb”、表“dbo.SuperHeroes”、列“HeroId”中。

我有两个型号:

超级英雄模型:

namespace SuperHeroesApi.Models
{
    public class SuperHero
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int HeroId { get; set; }

        [Required]
        [MaxLength(100)]
        public string Name { get; set; } 

       
        [MaxLength(100)]
        public string FirstName { get; set; } 

        [MaxLength(100)]
        public string LastName { get; set; }

        [MaxLength(100)]
        public string City { get; set; } 










    }
}
Run Code Online (Sandbox Code Playgroud)

电影型号:

 namespace SuperHeroesApi.Models
{
    public class Movie
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int MovieId { get; …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-web-api asp.net-web-api2 asp.net-core asp.net-core-webapi

0
推荐指数
1
解决办法
4万
查看次数