I'm using .NET Core Version 7 and I want to use EF Core to access a SQL Server Compact (*.sdf
) database file. What libraries to use and how to use Scaffold-DbContext
to build the existing database models and also the database has a password.
I want to use database first method. I added this library to the project:
ErikEJ.EntityFramework.SqlServerCompact,
Microsoft.EntityFrameworkCore.Tools
I have Sql Server Compact and SQLite/Sql Server Compact Toolbox installed,
But when I run Scaffold-DbContext
as follows, it gives this error:
Scaffold-DbContext "Data Source=Path\db.sdf;Password=***" -provider ErikEJ.EntityFramework.SqlServerCompact -Project "Databases" -Force -ContextDir "[Dir]\Context" -OutputDir "[Dir]" - UseDatabaseNames -NoPluralize
Error Text:
System.InvalidOperationException: Unable to find expected assembly attribute [DesignTimeProviderServices] in provider assembly 'ErikEJ.EntityFramework.SqlServerCompact'. This attribute is required to identify the class which acts as the design-time service provider factory for the provider. at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError) at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.CreateServiceCollection(String provider) 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, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable
1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Unable to find expected assembly attribute [DesignTimeProviderServices] in provider assembly 'ErikEJ.EntityFramework.SqlServerCompact'. This attribute is required to identify the class which acts as the design-time service provider factory for the provider.