英文:
When I add migration I get this error with .NET 7 Windows Forms app
问题
namespace ManegmentSystemCompany.Data.Context
{
public class ApplicationDbContext : DbContext
{
public DbSet<Catogry> Catogry { get; set; }
public DbSet<Custemer> Custemer { get; set; }
public DbSet<Employee> employees { get; set; }
public DbSet<Pruducts> pruducts { get; set; }
public DbSet<Stores> stores { get; set; }
public DbSet<Supplier> suppliers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=WhereHouseDb; Integrated Security=true");
}
}
}
After I run add-migration
, I get this error. I could not find a fix for it - help me please.
No suitable constructor was found for entity type 'Font'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'info', 'context' in 'Font(SerializationInfo info, StreamingContext context)'
Cannot bind 'prototype', 'newStyle' in 'Font(Font prototype, FontStyle newStyle)'
Cannot bind 'family', 'emSize', 'style', 'unit' in 'Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit)'
Cannot bind 'family', 'emSize', 'style', 'unit', 'gdiCharSet' in 'Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)'
Cannot bind 'family', 'emSize', 'style', 'unit', 'gdiCharSet', 'gdiVerticalFont' in 'Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)'
Cannot bind 'familyName', 'emSize', 'style', 'unit', 'gdiCharSet' in 'Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)'
Cannot bind 'familyName', 'emSize', 'style', 'unit', 'gdiCharSet', 'gdiVerticalFont' in 'Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)'
Cannot bind 'family', 'emSize', 'style' in 'Font(FontFamily family, float emSize, FontStyle style)'
Cannot bind 'family', 'emSize', 'unit' in 'Font(FontFamily family, float emSize, GraphicsUnit unit)'
Cannot bind 'family', 'emSize' in 'Font(FontFamily family, float emSize)'
Cannot bind 'familyName', 'emSize', 'style', 'unit' in 'Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit)'
<details>
<summary>英文:</summary>
![enter image description here](https://i.stack.imgur.com/8y4Lu.png)
![enter image description here](https://i.stack.imgur.com/aTfVm.jpg)
![enter image description here](https://i.stack.imgur.com/A8KuA.jpg)
namespace ManegmentSystemCompany.Data.Context
{
public class ApplicationDbContext : DbContext
{
public DbSet<Catogry> Catogry { get; set; }
public DbSet<Custemer> Custemer { get; set; }
public DbSet<Employee> employees { get; set; }
public DbSet<Pruducts> pruducts { get; set; }
public DbSet<Stores> stores { get; set; }
public DbSet<Supplier> suppliers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=WhereHouseDb; Integrated Security=true");
}
}
}
After I run `add-migration`, I get this error. I could not find a fix for it - help me please.
> No suitable constructor was found for entity type 'Font'. The following constructors had parameters that could not be bound to properties of the entity type:
>
> Cannot bind 'info', 'context' in 'Font(SerializationInfo info, StreamingContext context)'
> Cannot bind 'prototype', 'newStyle' in 'Font(Font prototype, FontStyle newStyle)'
> Cannot bind 'family', 'emSize', 'style', 'unit' in 'Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit)'
> Cannot bind 'family', 'emSize', 'style', 'unit', 'gdiCharSet' in 'Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)'
> Cannot bind 'family', 'emSize', 'style', 'unit', 'gdiCharSet', 'gdiVerticalFont' in 'Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)'
> Cannot bind 'familyName', 'emSize', 'style', 'unit', 'gdiCharSet' in 'Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)'
> Cannot bind 'familyName', 'emSize', 'style', 'unit', 'gdiCharSet', 'gdiVerticalFont' in 'Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)'
> Cannot bind 'family', 'emSize', 'style' in 'Font(FontFamily family, float emSize, FontStyle style)'
> Cannot bind 'family', 'emSize', 'unit' in 'Font(FontFamily family, float emSize, GraphicsUnit unit)'
> Cannot bind 'family', 'emSize' in 'Font(FontFamily family, float emSize)'
> Cannot bind 'familyName', 'emSize', 'style', 'unit' in 'Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit)'
</details>
# 答案1
**得分**: 1
没有找到适合实体类型 'Font' 的构造函数。
你是否希望将 Font 存储在数据库中?如果是的话,它需要一个 Entity Framework (EF) 能够用来创建实例的构造函数。有关规则的文档可以在这里找到:
你可以定义一个带有参数的构造函数,并在创建实体的实例时让 EF Core 调用这个构造函数。构造函数的参数可以绑定到已映射属性,也可以绑定到各种类型的服务,以便实现诸如延迟加载等行为。
如果你不希望将 Font 存储在数据库中,你需要将其排除在外。
[1]: https://learn.microsoft.com/en-us/ef/core/modeling/constructors
[2]: https://learn.microsoft.com/en-us/ef/core/modeling/entity-properties?tabs=data-annotations%2Cwithout-nrt#included-and-excluded-properties
<details>
<summary>英文:</summary>
> No suitable constructor was found for entity type 'Font'
Do you expect Font to be stored in the database? If so, it needs a constructor that EF can use to create instances. The rules are documented here:
> It's possible to define a constructor with parameters and have EF Core
> call this constructor when creating an instance of the entity. The
> constructor parameters can be bound to mapped properties, or to
> various kinds of services to facilitate behaviors like lazy-loading.
[Entity types with constructors][1].
If you don't expect to store Font in the database, you need to [exclude it][2].
[1]: https://learn.microsoft.com/en-us/ef/core/modeling/constructors
[2]: https://learn.microsoft.com/en-us/ef/core/modeling/entity-properties?tabs=data-annotations%2Cwithout-nrt#included-and-excluded-properties
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论