.net-core - 如何为现有 AzureCosmosDB 生成模型类?
问题描述
我有一个包含所有数据和集合的现有 Azure CosmosDB。现在我正在寻找基于我为 SQLServer 数据库所做的相同过程生成模型类。
https://www.learnentityframeworkcore.com/walkthroughs/existing-database
我使用导航到包含解决方案文件的文件夹的 cmd 实用程序尝试了以下命令:
dotnet ef dbcontext scaffold <Azure CosmosDB ConnectionString> Microsoft.EntityFrameworkCore.Cosmos -o Models
在执行上述命令时,我收到以下错误:
System.InvalidOperationException: Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly Microsoft.EntityFrameworkCore.Cosmos. This attribute is required to identify the class which acts as the design-time service provider factory.
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly Microsoft.EntityFrameworkCore.Cosmos. This attribute is required to identify the class which acts as the design-time service provider factory.
谁能帮我知道如何解决这个问题?
解决方案
为了使其工作,数据库提供程序需要包含有关如何进行脚手架的信息。目前,CosmosDB 不支持此功能,因此您将无法使用 CLI 从现有数据库创建模型。
有一个Github 问题开放以改进错误消息以使其更清晰。如果您愿意,可以在该存储库上打开一个问题,请求为 Cosmos 添加该功能。
推荐阅读
- python - 在后台运行 pyshark
- javascript - onclick 后清除搜索框
- stm32 - 无法在 CubeMX 上为双核 STM32H MCU 生成代码
- javascript - 在数据库中存储大量数据的最佳方法
- r - 如何使用 str_sub?
- python - 在 django 中使用 DeleteView 成功删除后尝试返回上一页时出现“找不到页面”错误
- sql - 如何使用 BigQuery 获取平均时间间隔(5 分钟)或记录数
- android - Android 10:android:foregroundServiceType="mediaProjection" 无法使用服务
- python - 基于重复的日期时间索引,用另一个数据帧中的值覆盖一个数据帧
- eclipse-hono - 从源代码构建荣誉时运行集成测试时出错 - 证书已过期