Entity framework core EF Core只读属性和参数化构造函数不起作用
型号:Entity framework core EF Core只读属性和参数化构造函数不起作用,entity-framework-core,Entity Framework Core,型号: 类模型{ 公共Guid OwnerIdentityGuid{get;}//只读属性 私有模型(Guid ownerIdentityGuid)//camelCase约定应该有效 { OwnerIdentityGuid=OwnerIdentityGuid; } } 模型配置: /。。。 模型配置 .Property(m=>m.OwnerIdentityGuid) .ValueGeneratedNever();//应该使它与只读属性一起工作 // ... 运行dotnet ef migra
类模型{
公共Guid OwnerIdentityGuid{get;}//只读属性
私有模型(Guid ownerIdentityGuid)//camelCase约定应该有效
{
OwnerIdentityGuid=OwnerIdentityGuid;
}
}
模型配置:
/。。。
模型配置
.Property(m=>m.OwnerIdentityGuid)
.ValueGeneratedNever();//应该使它与只读属性一起工作
// ...
运行dotnet ef migrations add InitialMigration
时,出现以下错误:
找不到实体类型“Model”的合适构造函数。以下构造函数的参数无法绑定到实体类型的属性:无法在模型(Guid ownerIdentityGuid)中绑定“ownerIdentityGuid”
增加私有集属性的代码>修复了该问题。如何使其与只读属性一起工作
使用以下版本的EF Core软件包:
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的
----编辑
这实际上是可行的,这是我的“真实”代码中的错误配置。它对我有效(无需复制)。注意到EFCore.NamingConventions
第三方扩展,您确定没有弄乱它吗?我正在使用选项。使用SnakeCasenamingConvention()
但它只更改db列名(我注释掉了它,仍然收到相同的错误)。好的,发现了问题,我的EntityTypeConfiguration正在扩展其他EntityTypeConfiguration并以wron方式调用base()。我的错,对不起,谢谢你的帮助。