Fadhly Permata
Fadhly Permata

Reputation: 1686

Entity Framework Generator For Postgres

I found a nice article in http://www.loresoft.com/Generate-ASP-NET-Web-API. I've read and test it with the SQL Server database with success. Now, I want to change the database engine into PostgreSQL, I've migrated the database from SQL Server into PostgreSQL.

But, When I am executing:

efg generate -c ""Host=localhost;Username=admin;Database=dbTest;Password=admin;Persist Security Info=True""

The console showing me:

17:18:04 W Option file not found: generation.yml
17:18:04 I Using default options
17:18:04 D Creating database model factory for: SqlServer
17:18:04 I Loading database model ...
17:18:04 F Host terminated unexpectedly
System.ArgumentException: Keyword not supported: 'host'.
   at Microsoft.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
   at Microsoft.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
   at Microsoft.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
   at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
   at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
   at EntityFrameworkCore.Generator.CodeGenerator.GetDatabaseModel(IDatabaseModelFactory factory) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\CodeGenerator.cs:line 371
   at EntityFrameworkCore.Generator.CodeGenerator.Generate(GeneratorOptions options) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\CodeGenerator.cs:line 40
   at EntityFrameworkCore.Generator.GenerateCommand.OnExecute(CommandLineApplication application) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator\GenerateCommand.cs:line 76
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at EntityFrameworkCore.Generator.Program.Main(String[] args) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator\Program.cs:line 50

I think I was missing some dependencies package. But, I am not sure what is it.

Thank you very much

Upvotes: 0

Views: 834

Answers (1)

Fadhly Permata
Fadhly Permata

Reputation: 1686

I've found the solution, and decide to post it here because It may help other people in the future.

Actually, efg command will use SqlServer provider if we not mentioning any "provider" parameter. So, I've revised my command into:

efg generate -c "Host=localhost;Username=admin;Database=dbTest;Password=admin;Persist Security Info=True" -p PostgreSQL

Upvotes: 2

Related Questions