edmx and tt files are not supported by EF core. you need to use ef core scaffolding instead, and regenerate the classes.
try the documentation:
[https://learn.microsoft.com/en-us/ef/efcore-and-ef6/porting/port-edmx
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am porting an application from ASP.net MVC 5 to ASP.net Core MVC and I reach out in the area pointing the Entity Framework related modules.
I have the generated classes and I also have the edmx and tt files, I added the files to a newly created Class Library (.net core) it seems like it needs to be regenerated (or im not sure), the edmx cannot be opened (and there are no errors),
I have tried to manualy update the derived models to use an updated libraries to use
"using Microsoft.EntityFrameworkCore;"
but i feel that these models needs to be regnerated instead of doing them manualy.
One thing I observe is it also finds for ConfigurationManager instead of the appsettings.json for .net core.
WHat is the proper way of doing this?
Summary
I have edmx and tt files, and i have the generated files as well, How can I use it for ASP.net Core MVC 6.0, does it need to be regenerated?
What is the proper way of doing this? (porting the entity framework 6 stuff to be used in ASP.NET Core MVC)
edmx and tt files are not supported by EF core. you need to use ef core scaffolding instead, and regenerate the classes.
try the documentation:
[https://learn.microsoft.com/en-us/ef/efcore-and-ef6/porting/port-edmx
What is the proper way of doing this?
You will be able to use the context class and entity class generated by the reverse engineering. See the following documents for details:
Reverse Engineering
https://learn.microsoft.com/en-us/ef/core/managing-schemas/scaffolding/?tabs=dotnet-core-cli
Scaffold-DbContext
https://learn.microsoft.com/en-us/ef/core/cli/powershell#scaffold-dbcontext
What is the proper way of doing this?
You will be able to use the context class and entity class generated by the reverse engineering. See the following documents for details:
Reverse Engineering
https://learn.microsoft.com/en-us/ef/core/managing-schemas/scaffolding/?tabs=dotnet-core-cli
Scaffold-DbContext
https://learn.microsoft.com/en-us/ef/core/cli/powershell#scaffold-dbcontext
One option is to use a Visual Studio extension EF Power Tools to reverse engineer your database which is easier than manually scaffolding your database.
See my article on using EF Power Tools.
Note that EF Power Tools will place the connection string in the DbContext which can be removed and placed into appsettings.json.
Change the connection string
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MockupApplication;Integrated Security=True"
}
}
In Program.cs
var configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.Build();
Then
builder.Services.AddDbContextPool<Context>(options =>
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));