Trying to wire up to use Entity Framework with Umbraco EFCoreContext in a separate logic project but can seam to getting working. Anyone done this before?
The biggest issue I ran into was the using statement for IEFCoreScope in the controller.
Instead of this type of declaration:
using IEfCoreScope<MyContext> scope = _efCoreScopeProvider.CreateScope();
I had to use the traditional type:
using IEfCoreScope<MyContext> scope = _efCoreScopeProvider.CreateScope() {
//Do DbContext things
}
Aside from that I setup a traditional Api to grab third party data and import it to the database.
If you have any specific questions, I'd be glad help also, since it is fresh in my mind.
As the AddUmbracoEFCoreContext needs AddUmbraco before and that seams wrong in this case to add Umbraco with all whistles and bells? Or maybe it should add a slimed down version of the AddUmbraco statement? Anyone have a "core" AddUmbraco setup that one is supposed to use instead?
Got it working so that migrations can be in the logic project now.
Had to make a custom IDesignTimeDbContextFactory in the logic project that ef migrations use.
public class CommerceDesignTimeContextFactory : IDesignTimeDbContextFactory<CommerceContext>
{
public CommerceContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<CommerceContext>();
optionsBuilder.UseSqlServer();
return new CommerceContext(optionsBuilder.Options);
}
}
Wire up as recommended in the web project that references the separate project.
Great! Glad you got it working. Yes that is a very similar approach that I took.
I've built my migrations by hand and installed any required umbraco packages in the logic project to satisfy dependencies. As a temporary measure for testing I setup a pre-build script that copies AppCode/* and AppPlugins/* to the web project for execution and testing. Eventually I will roll that logic project into a nuget package and install it into my main site.
Entity Framework in Umbraco 12 and custom tables in a separate logic project
Trying to wire up to use Entity Framework with Umbraco EFCoreContext in a separate logic project but can seam to getting working. Anyone done this before?
Seen this but when having a separate project, that isnt running the "Umbraco"? https://docs.umbraco.com/umbraco-cms/tutorials/getting-started-with-entity-framework-core
Hello Anders,
I've been working recently on a similar project. I found this article by Jon Jones extremely helpful;
https://www.jondjones.com/learn-umbraco-cms/umbraco-12-tutorials/how-to/custom-database-tables-with-umbraco-12-and-entity-framework-deep-dive/
The biggest issue I ran into was the using statement for IEFCoreScope in the controller.
Aside from that I setup a traditional Api to grab third party data and import it to the database.
If you have any specific questions, I'd be glad help also, since it is fresh in my mind.
Have a great day, --Mark
Hi,
Did you run this in a separate project from the "umbraco" web project?
Can seam to wire up the dbcontext in the separate project any other way than with EF standard way.
As the AddUmbracoEFCoreContext needs AddUmbraco before and that seams wrong in this case to add Umbraco with all whistles and bells? Or maybe it should add a slimed down version of the AddUmbraco statement? Anyone have a "core" AddUmbraco setup that one is supposed to use instead?
Got it working so that migrations can be in the logic project now. Had to make a custom IDesignTimeDbContextFactory in the logic project that ef migrations use.
Wire up as recommended in the web project that references the separate project.
Great! Glad you got it working. Yes that is a very similar approach that I took.
I've built my migrations by hand and installed any required umbraco packages in the logic project to satisfy dependencies. As a temporary measure for testing I setup a pre-build script that copies AppCode/* and AppPlugins/* to the web project for execution and testing. Eventually I will roll that logic project into a nuget package and install it into my main site.
--Mark
is working on a reply...