当前位置: 代码迷 >> 综合 >> 【2021-04-16】The following constructors had parameters that could not be bound to properties
  详细解决方案

【2021-04-16】The following constructors had parameters that could not be bound to properties

热度:62   发布时间:2023-12-14 20:16:35.0

System.InvalidOperationException HResult=0x80131509 Message=No
suitable constructor was found for entity type ‘Movie’. The following
constructors had parameters that could not be bound to properties of
the entity type: cannot bind ‘dierctory’ in ‘Movie(string dierctory)’.
Source=Microsoft.EntityFrameworkCore StackTrace: at
Microsoft.EntityFrameworkCore.Metadata.Conventions.ConstructorBindingConvention.ProcessModelFinalizing(IConventionModelBuilder
modelBuilder, IConventionContext`1 context)

问题:

我的代码Movie类有“有参”构造函数,但EF Core在初始化数据库时,无法使用“有参”构造函数初始化。参考StackOverflow。
详见微软文档

解决方案:

添加默认的构造函数,重载构造函数。
在这里插入图片描述

  相关解决方案