Greetings i have an existing database and i was going to build my application using ASP.NET Core, based on this tutorial, i've installed the packages for Entity Framework core, now i have to reverse my tables, so as tutorial said i used this command:
Scaffold-DbContext "Server=
(localdb)\mssqllocaldb;Database=RFID;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
However it keeps getting me this error:
Invalid JSON file in C:\Users\user11\documents\visual studio
2015\Projects\CoreOAS\src\CoreOAS\project.json
what should i do?
If you have a comment like below then above error will emit.So you have to remove that.
Wrong :
// required for EF <--- this is the issue
"buildOptions": {
"emitEntryPoint": true
},
Correct way :
"buildOptions": {
"emitEntryPoint": true
},
You can read more about it here : their (JSON) decision not to support comments
Related
I'm using core 3 and I have included below packages to my project
"Microsoft.EntityFrameworkCore.Design": "5.0.7",
"Microsoft.EntityFrameworkCore.SqlServer": "5.0.7",
"Microsoft.EntityFrameworkCore.Tools": ""5.0.7""
And here is my connection string and I have tested the connection before and it succeeded
"ConnectionStrings": { "bikeStore": "Data Source=localhost;Initial Catalog=BikeStore;User ID=sa;Password=***********" }
Now I want to run the Scaffold command as below
Scaffold-DbContext Data Source=localhost;Initial Catalog=BikeStore;User ID=sa;Password=***********Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data
And I got below error
Build started...
Build succeeded.
Unable to find provider assembly 'Source=localhost'. Ensure the name is correct and it's referenced by the project.
Here's the Server Explorer and how I connected to my db
What is wrong with my approach?
You can replace Data Source with Server and provide the provider flag:
Scaffold-DbContext -Connection "Server=localhost;Initial Catalog=BikeStore;User ID=sa;Password=***********;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data
Microsoft.EntityFrameworkCore 3.1.31
Microsoft.EntityFrameworkCore.SqlServer 3.1.31
Microsoft.EntityFrameworkCore.Tools 3.1.31
dotnet ef Scaffold-DbContext "Server=.; Initial Catalog=CourseDB;User ID=sa; Password=sa;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
I have a Firebird database with tables. I need to generate DbContext, models etc. So provider installed:
Connection string is OK:
Console.WriteLine("Starting");
FbConnection db = new FbConnection(csb.ToString());
db.Open();
Console.WriteLine($"Database state:{db.State.ToString()}");
Db connection is Ok:
Trying to create models using command:
Scaffold-DbContext "user id=ХХХ;password=ХХХ;database=ХХХ;data source=localhost;port number=3050"FirebirdSql.EntityFrameworkCore.Firebird -OutputDir Models
looks good:
However, DBcontext is empty:
You are using FirebirdSql.EntityFrameworkCore.Firebird (7.10.1). This version doesn't support DbContext scaffolding.
Try version-8.0.0 (currently in alpha3).
I'm trying to do ModelFirst (scaffolding) of an existing bbdd in postgresql with geometry data.
In the VS project I have well installed all the necessary nuget packages (EntityFrameworkCore, EntityFrameworkCore.Design, EntityFrameworkCore.Relational, EntityFrameworkCore.Tools, Npgsql.EntityFrameworkCore.PostgreSQL, Npgsql.EntityFrameworkCore.PostgreSQL.Design and Npgsql.NetTopologySuite).
In VS PM, when launching the command:
Scaffold-DbContext "Host=myserver;Database=spatial;Username=postgres;Password=xxxxxxxx" Npgsql.EntityFrameworkCore.PostgreSQL -Schemas spu -OutputDir Spatials
He gives me these exceptions:
Could not find type mapping for column 'spu.nuts.geom' with data type
'geometry(Geometry,4326)'. Skipping column.
And it doesn't map the geometry columns, all rest columns are ok.
What am I doing wrong?
Can I specify scaffolding using NetTopologySuite?
Thanks a lot
Edit: Solved.
Show comments
I am trying to connect sails 1.0 to SQL Server, but I've been out of luck so far. There doesn't seem to be anything publicly available.
I did found someone on GitHub that did try to add support, although when i try to use their branch it didn't work out too well.
Got this error when I try to use the model.findOne() method.
name: 'RequestError',
message: 'Incorrect syntax near \'BY\'.',
code: 'EREQUEST',
number: 102,
lineNumber: 1,
state: 1,
class: 15,
serverName: 'sql1b',
procName: '',
precedingErrors: [] }
Was anyone else more lucky in getting sails 1.0 to work with a SQL Server database?
Yes, you can try sails-sqlserver-sailsv1. But don't follow the guide in the npm site, probably a copy/paste error on how to install the package. use:
npm install sails-sqlserver-sailsv1 --save
And in the datastore configuration on sails make sure to use the correct adapter name:
default: {
adapter: 'sails-sqlserver-sailsv1',
user: 'cnect',
password: 'pass',
host: 'abc123.database.windows.net' // azure database
database: 'mydb',
options: {
encrypt: true // use this for Azure databases
}
}
I hope it helps you.
You may want to change from waterline - default SailS ORM - to Sequelize + Tedious. Waterline is very dependent on the work of the opensource community, and thus SQL Server is not (and I don't think it will ever be) supported.
In my sails application I edit the config/models.js file as follows to clean the database when lifting the application.
migrate: 'drop',
connection: 'mongodb'
But when I try to run the application it displays the following error.
A hook (`orm`) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
MongoError: Index with name: _id_ already exists with different options
I am using sails version 0.10.5 ,any kind of help would be appreciated.
same here, when you have an error to the model the orm crashes, at least you have the error, sometimes with mysql you don't even have the error
the issue was, in some of my application's model files I have added following to attributes list.
attributes: {
_id: {
type: 'string',
unique: true
}
}
since I have added unique true to the attribute, it causes an error when I try to clean the collections on start up. more information about this issue can be found on Index already exists with different options error while using createIndex() in latest MongoDB java driver