Scaffolding Oracle database using DB First Approach - c#

"Unable to find provider assembly 'Oracle.ManagedDataAccess.Core'. Ensure the name is correct and it's referenced by the project".
Dont Know why this error is comming while scaffolding.
Scaffold command i used.
Scaffold-DbContext -Provider Oracle.ManagedDataAccess.Core -Connection "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=18.88..)(PORT=11))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=CC)));User Id=CC;Password=C**8;" -OutputDir Models .
These are the package reference in my project
 

Related

could not load assembly '{library project}'. Ensure it is referenced by the startup project '{winforms project}' using Scaffold-DbContext

I have a class library project that is referenced by a Winforms project in .NET Core 6.
In package manager, I run this when selected the class library project.
Scaffold-DbContext "Data Source=localhost;Initial Catalog=ControlParking;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/DB -Force
After that, this error is shown:
PM> Scaffold-DbContext "Data Source=localhost;Initial Catalog=ControlParking;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/DB -Force
Build started...
Build succeeded.
Could not load assembly 'Manager'. Ensure it is referenced by the startup project 'ParkControlWin'.
Where Manager is the class library project and ParkControlWin is the winforms project. ParkControlWin is actually referencing Manager project.
When I build the whole solution, no errors are shown, just some warnings, for example, variables are never used, and so on.
What may be happening here?

Scaffolding an existing SQLite database with EF core results in a generic context and no entities for the tables

The command I'm inputting into pmc is
Scaffold-DbContext "DataSource=C:\SQLite\Databases\Ticket0.db3" Microsoft.EntityFrameworkCore.Sqlite -OutputDir C:\WPFTutorials\TicketEF\TicketEF\DB -context TicketContext -force
I've checked and double checked the data source, but it only generates a generic context and no tables (I can't include images as I don't have high enough reputation).
I also checked on stack overflow but the closest relevant post I could find was this SQLite scaffolding with Entity Framework Core, however the problem there was relative pathing whereas I am using an absolute path.
Another I tried was Scaffold (reverse engineering) existing database return empty sets and tried commenting out the <Nullable>enable</Nullable> which solved their issue but that didn't work either.
I have the
Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.Sqlite and Microsoft.EntityFrameworkCore.Tools
NuGet packages installed.
In case it matters the database I am trying to connect can be opened and changed in SQLiteStudio so it should be working fine, and it has 5 tables and 2 views.
I have modified your code to the below and it's working.
Scaffold-DbContext -provider Microsoft.EntityFrameworkCore.Sqlite "DataSource=C:\SQLite\Databases\Ticket0.db3" -OutputDir C:\WPFTutorials\TicketEF\TicketEF\DB -context TicketContext -force
What had happened was that I mistyped the database location as "Ticket0" which is how it appeared in SQLiteStudio and EF Core generated an empty Ticket0.db3 which I'd then mistaken for the original file.
Since it's my own mistake should I delete the question?

Difficulties connecting to database through Scaffold-DbContext

I am learning ASP.NET core 6 Multitier architecture. I tried making connection to database but I keep getting this error:
Error Number:4060,State:1,Class:11
Cannot open database "Blogging" requested by the login.
The login failed.
Login failed for user 'TECHRITOMA\TECHRITOMA Inc'.
I tried using the command :
Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
and i was expecting the model class to be created.
As Sydney_dev said. First, Visual studio needs to successfully connect to the local database. Official document: SQL Server Express LocalDB.
.NET Core+EF Scaffold-DbContext command uses.
Scaffold-DbContext "Data Source=ip address;Initial Catalog=database name;User ID=account;password=password;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models;
Scaffold-DbContext "Data Source=ip address;Initial Catalog=database name;User ID=account;password=password;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables "Blog","Post" -ContextDir Context -Context BlogContext - ContextNamespace New.Namespace
Official document.

How can I create the database entities in a layered application

I have to create a layered .net core application including a database. I want to build the database entities with sql-first approach. The solution looks like this:
All of the projects are class libaries, except the FoodSupplementCompany.Program.
My question is, how can I use Scaffold-DbContext to generate the entities to the FoodSupplementCompany.Data project?
You can use the Package Manager Console:
cd .\FoodSupplementCompany.Data
dotnet ef dbcontext scaffold -s ..\FoodSupplementCompany.Program
The line cd .\FoodSupplementCompany.Data is for navigating into project directory where the DBContext is located.
And the line -s ..\FoodSupplementCompany.Program is for stating where is the startup project to use.
As the guide here states: scaffold-dbcontext
Example:
Scaffold-DbContext
"Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models
-OutputDir -> The directory to put files in. Paths are relative to the project directory.

Connection String Error "Missing its statement block"

I am using the updated Nuget Package Manager Console in Visual Studio to scaffold models from a database I've connected from named Sail. When I enter the connection string into the Package manager console.
PM> Data Source=localhost;Initial Catalog=Sail;Integrated Security=True
I receive the following errors:
At line:1 char:12
+ Data Source=localhost;Initial Catalog=Sail;Integrated Security=True; ...
The Data section is missing its statement block.
Found my answer:The block below successfully generates models from the connected "Sail" SQL database.
Scaffold-DbContext –Connection "Server(localdb)\mssqllocaldb;Database=Sail;Trusted_Connection=True;"
(localdb)\mssqllocaldb;Database=Sail;Trusted_Connection=True;"
-Provider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "Models" –Context "Sail" –Verbose -Force

Categories