[SOLEVED] Help with EF core Migration for Umbrac 1...
# help-with-umbraco
l
I am on my way to create some custom database tables i have follow this pice og documentation https://docs.umbraco.com/umbraco-cms/tutorials/getting-started-with-entity-framework-core But when i try the CLI command "dotnet ef migrations add AddResevertionTables --context ..." I get an error: Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Project.WebSite.Infrastructure.DbContexts.ProjectDbContext]' while attempting to activate 'Project.WebSite.Infrastructure.DbContexts.ProjectDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 But have no clue why this happign and can not move on can somebody help me
j
Is your context in a seperate project to your umbraco site?
l
@Jemayn nope
j
And you already have your dbContext file set up and registered? I have a repo for a blogpost I wrote a while back where it definitely worked, feel free to have a look at the context and registration: https://github.com/jemayn/efcore-and-uibuilder/blob/main/TwentyFourDays.Persistence/DbContexts/MovieContext.cs
l
public class ProjekctDbContext(DbContextOptions options) : DbContext(options) { public required DbSet ReserveSeat { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { .... } }
And in startUp.cs services.AddUmbracoDbContext((serviceProcider, options) => { options.UseUmbracoDatabaseProvider(serviceProcider); });
dont mind the spelling mistake on project is just to screw the customers real name 🙂
@Jemayn I can see you ex, use Umbraco 12.x.x I have aother customer witch running EF core with customer table i same version, and everything work. But this new one, where we run .net 8 and Umbraco 13 then the add migrations just wont run
j
Hmm it runs just fine on this v13 project I am working on, just can't share code and the setup is a bit more complicated. We do however register the contexts a bit differently on this project as the "new" way still doesnt support targeting a seperate site, so maybe the UseUmbracoDatabaseProvider method is not working so well?
We're using this on v13 without issue:
Copy code
csharp
services.AddUmbracoEFCoreContext<FavouriteListContext>((options, connectionString, providerName) => options.UseSqlServer(connectionString,
            builder =>
            {
                builder.MigrationsAssembly(typeof(DependencyInjection).Assembly.GetName().FullName);
            }));
l
have tryed to replace the UseUmbracoDatabaseProvider with UseSqlServer but again no luck
j
Then I don't think I can help, good luck though - may warrant an issue on the tracker
l
no worries but thanks for trying a least 🙂
Hey @Jemayn Fund the issue, the line in our code config.AddAzureKeyVault(validUri, new DefaultAzureCredential()); fucks everything up, do i delete that line or the configurated connectionstring then everything works 🙂
j
Oh strange, we aren't using azure keyvault so I guess not a problem I've hit - sounds really strange though 😄
l
@Jemayn with --versone could i see what happen is then runtime hit the line it try to start a connection to azure, but get an 401 response and makes a panicException so then Ef panic afterwords 😄
j
Ahh ok makes sense
305 Views