Closed Inlustris closed 6 years ago
Hey Luc,
Entity Framework doesn't' have a specification on .Net Standard, so EF has his own implementation for .Net Framework and .Net Core (very different in both frameworks), so as you know, .Net Standard is the specification, but EF hasn't specifications on .Net Standard that's why the implementations are very different, actually, they are different "things", EF and EF Core, respectively. Having said that, there is no EF Standard specification and it can't target multiple frameworks. I imagine you went with .Net Standard because you want to support multiple frameworks, but if that's not the case, I recommend you to switch to .Net Core in order to you can use EF Core.
Hello Giovani,
I would like to create the .net standard library to get those multiple frameworks. But it looks like this is not possible the way i want to do it. The solution i used is to dependency inject my database in the .NetCore application. And not passing the responsibility to the library itself.
I have another question: When i use
Am i forgetting something or am i doing something wrong?
Kind regards, Luc
Hi Luc,
Can you provide me an example of what are you doing exactly, please?
Hello Giovani,
I'm trying to update my database by creating a new migration in EFCore. To create this migration there has to be a dbcontext present. It looks like when i'm using Services.AddDbContectFactory. The program does not recognize the database. When i use Services.AddDbContext it is recognized.
In the code block below you can see that I add my dbcontext twice, one in the shape of a factory one in the shape of the context itself.
webHostBuilder = webHostBuilder.ConfigureServices(services =>
{
services.AddMvc();
services.AddDbContext<DeviseContext>(builder => builder.UseSqlServer(config.GetConnectionString("DefaultConnection")));
services.AddDbContextFactory<DeviseContext>(builder => builder.UseSqlServer(config.GetConnectionString("DefaultConnection")));
services.Configure<AppSettings>(config.GetSection("AppSettings"));
});
If it is possible i would like to remove the AddDbContext
What i could do is add:
#if DEBUG
#Endif
This way i can create migration and update the database in debug but this is in my opinion not the way to go.
I tried several solutions to fix this but none of them work. When researching the problem. This problem comes up when migrating from a lower version to EF core 2.0. in this Link they talk about it.
But there is no solution to the problem that it is causing.
For now i will use the AddDbContext but like i said i would like to remove it because it is never used.
Kind regards, Luc
Luc,
I'm planning to release that feature tomorrow or in the worst case until Friday, in order to EFCore.DbContextFactory
supports migrations implicitly and you don't have to implement IDesignTimeDbContextFactory
for your context , so, I'll let you know when the new version will be available.
Thanks for share your issue and use the project!
Heey Giovani,
That is nice to hear. I'm looking forward to it.
Thank you for this feature.
@Inlustris the new version is released, you can update it!
Heey Giovani,
Thank you for the update. I will use it in the upcoming days.
Heey Giovani (it's me again),
I'm trying to split my project in to multiple projects. Now i have a seperate project for my repository layer. I would like to do services.AddDbContextFactory on this project but it is a .netstandard project.
Only the project that is using the different libraries is configured as .netcore. This way i have to register the database at the application instead of the project where it came from. Is there a way to do the services.AddDbContextFactory from a .netstandard library that is implemented by a .netcore application.
Kind Regards, Luc