Closed mohamadhasansalmaaniyaan72 closed 10 months ago
ErikEJ.EntityFramework.SqlServerCompact is a EF 6 "Classic" provider and you can use the Entity Framework Tools installed with Visual Studio to generate database first code with that provider.
Scaffold-DbContext "Data Source=....." -provider ErikEJ.EntityFramework.SqlServerCompact
That is, what should I use in the provider section to convert the tables into models and add them to the project.
Because I have also used EntityFrameworkCore.SqlServerCompact40
in the provider part and it does not create and gives an error
EntityFrameworkCore.SqlServerCompact40 only works with .NET Framework or .NET Core 2.2
So what should be left? If you need a library or something else, tell me. thanks
What do you mean by "left"???
ErikEJ.EntityFramework.SqlServerCompact is a EF 6 "Classic" (not EF Core!) provider and you can use the Entity Framework Tools installed with Visual Studio to generate database first code with that provider.
What I meant by the previous comment is, so what provider should be used, since all that you say is installed on Windows. I have used all the providers, but it does not convert the tables into models. I wrote all the errors and updated the post.
You CANNOT use "Scaffold-DbContext" with SQL Server Compact and .NET 6 or later - it is simply not supported.
What you can do is use my Entity Framework (not Core!) provider, as described here:
https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/existing-database
ErikEJ.EntityFramework.SqlServerCompact -Version 6.4.0-beta4
What has changed in this version? Will scaffold-dbcontext
be added in the final version?
And what does it mean that it is simply not supported? It means that I have to do something else, or the problem is with .net core or the problem is with the library.
ErikEJ.EntityFramework.SqlServerCompact is not an EF Core package and will never support scaffold-dbcontext command.
It is an Entity Framework Classic package.
But it will enable you to use SQL Server Compact with .NET 7, which is what you are asking for, is it not?
Did you read the link above?
Yes, I read the link above, I wanted to use the newer version. Does this mean that this version only supports the Code First method and in the final version it will not support the database first method written with scaffold-dbcontext
at all? (As a suggestion and feedback, do this in the final version if possible.)
The provider is not an EF Core provider and supports database first as described in the link (code first from database, but it is the same thing). Suggest you read and study some documentation sites.
@mhsalmanian72 I have created a draft blog post here, that explains the (somewhat complicated) workflow: https://github.com/ErikEJ/erikej.github.io/blob/master/_drafts/2023-xx-xx-sqlce-net7-ef6.md
Thank you
What library is required for this code only?
DbConfiguration.SetConfiguration(new SqlCeDbConfiguration())
Because it doesn't recognize this namesapce:
using System.Data.Entity.SqlServerCompact;
If I want instead of the above code In the Context class, in the OnConfiguring method, write the following code:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlCe(connection);
}
What should I do, is it possible or not?
Because when I add the EntityFrameworkCore.SqlServerCompact40 library, the UseSqlCe method is added, but it gives an error in execution.
Error text:
Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptionsExtensionWithDebugInfo' from assembly 'Microsoft.EntityFrameworkCore, Version=7.0.10.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'
It is all explained in the draft blog post.
EntityFrameworkCore.SqlServerCompact40 is a peprecated .NET Core 2.2 provider and does NOT work with .NET 6 or later (as I have tried to explain many many times)
@mhsalmanian72 I have now published the blog post https://erikej.github.io/sqlce/entityframework/2023/09/27/sqlce-net7-ef6.html
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:
If the problem is with the provider, what library should be added to the project and what provider should be written?
I have Sql Server Compact and SQLite/Sql Server Compact Toolbox installed, But when I run
Scaffold-DbContext
as follows, it gives this error:EntityFrameworkCore.SqlServerCompact40] ....
Error Text When I am using ErikEJ.EntityFramework.SqlServerCompact library:
Error Text When I am using EntityFrameworkCore.SqlServerCompact40 library: