Alex Wilks
07/16/2024, 10:02 AMInvalid object name 'Company'.
is the precise error message). After digging around, I can see that the scope provider that gets injected into our repository is pointing to the default Umbraco connection string even though we set the correct connection string in the application startup:
services.AddUmbracoDbContext<CustomDBContext>(options =>
{
options.UseSqlServer("name=ConnectionStrings:CustomDB");
});
I'm at a bit of a loss as to why this would be the case. Does anyone have any ideas?
ThanksPaul Marden
07/16/2024, 12:37 PMMatt Brailsford
07/16/2024, 12:48 PMAddUmbracoDbContext
? This doesn't look standard. And I guess the scope provider using the default umbraco connection string is correct because it knows nothing about EFCore so when implementing your repository, because your are bypassing the default logic, it's your responsibility to handle this. Might be worth trying the config option also to provide an alternative connection string https://docs.umbraco.com/umbraco-ui-builder/collections/the-basics#setconnectionstring-string-connectionstringname-collectionconfigbuilder-less-than-tentitytype-greateAlex Wilks
07/16/2024, 1:39 PMAddUmbracoDbContext
is the way of adding an additional DB context that is suggested by the Umbraco documentation
* Based on the UI Builder documentation, it looks like using SetConnectionString
doesn't give us the overrides that repositories does and we need that to be able to save data in multiple places when saving our content.Andrew McKaskill
07/17/2024, 8:30 AMAlex Wilks
07/17/2024, 9:57 AMpublic class CompanyUIBuilderRepository : Repository<Company, int>
{
private readonly IEFCoreScopeProvider<CustomDBContext> _scopeProvider;
public CompanyUIBuilderRepository(RepositoryContext context, IEFCoreScopeProvider<CustomDBContext> scopeProvider) : base(context)
{
_scopeProvider = scopeProvider;
}
}
If I break things here and inspect scopeProvider._scopeProvider.DatabaseFactory.ConnectionString
, it has the Umbraco DB connection string and not the one set in our startup.cs.
This, I believe, is the reason that we get the error that the Company table doesn't exist - we're looking to the wrong DB and I don't know why.Matt Brailsford
07/17/2024, 1:02 PMIEFCoreScopeProvider
and how it's created so not sure how that has the wrong connection. If this is being provided by a CMS provided API, then I think is potentially more of a CMS issue, than a UI Builder issue.
Maybe Andrew can provide details on how his repository is setup.Alex Wilks
07/17/2024, 1:08 PMMatt Brailsford
07/17/2024, 1:11 PMAlex Wilks
07/18/2024, 1:09 PMSebastiaan
07/18/2024, 1:32 PMMatt Brailsford
07/19/2024, 6:53 AMAndrew McKaskill
08/05/2024, 9:43 AMIEFCoreScopeProvider
is a scope provider created by Umbraco to create new scopes for the Umbraco database tables using entity framework (instead of NPoco).
You need to inject YOUR context (with the other connection string) into the Repository instead.
Let me have a quick review of my classes and see what code snippets I can share.Andrew McKaskill
08/06/2024, 10:35 AM