Question: can we specify which method are we using in different namespace?
I am using .NET 6.0 framework with Microsoft.EntityFrameworkCore (6.0.10) & Elsa.Persistence.EntityFramework.SqlServer (2.9.2).
Code in my Program.cs
:
using Elsa.Persistence.EntityFramework.SqlServer;
using Microsoft.EntityFrameworkCore;
...
// for Elsa workflow
builder.Services.AddElsa(elsa => elsa
.UseEntityFrameworkPersistence(ef => ef.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")))
.AddConsoleActivities()
.AddHttpActivities(elsaSection.GetSection("Server").Bind)
.AddJavaScriptActivities());
...
//for existing db connection
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
});
...
Connection strings in my appsettings.json
:
"ConnectionStrings": {
"DefaultConnection": "server=.\\SQLExpress; Database=ESEApplicationFormWebApp;uid=kelsey;pwd=12345678;MultipleActiveResultSets=true"
}
I get this error:
Error CS0121: The call is ambiguous between the following methods or properties are happening at both .UseSqlServer()
Error 1 - UseSqlServer() in elsa-workflow
Error 2 - UseSqlServer() in existing database connection
The call is ambiguous between the following methods or properties: 'Elsa.Persistence.EntityFramework.SqlServer.DbContextOptionsBuilderExtensions.UseSqlServer(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder, string, System.Type?)' and 'Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder, string, System.Action<Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder>?)'
I think the problem is I had installed two NuGet packages with the same method name.
I tried to edit the whole namespace like this but error CS0234 is triggered "The type or namespace name 'UseSqlServer' does not exist in the namespace 'Microsoft.EntityFrameworkCore' (are you missing an assembly reference?)"
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
Microsoft.EntityFrameworkCore.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
});
Reference:
https://v2.elsaworkflows.io/docs/quickstarts/elsa-dashboard-and-server
https://elsa-workflows.github.io/elsa-core/docs/next/installation/installing-persistence
Just remove the one of two problematic using. Since those methods are extension methods (so static method) you could use them as static method :
using Elsa.Persistence.EntityFramework.SqlServer;
using Elsa.Persistence.EntityFramework.Core.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddElsa(elsa => elsa
.UseEntityFrameworkPersistence(ef =>
{
ef.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
})
.AddConsoleActivities()
.AddHttpActivities(elsaSection.GetSection("Server").Bind)
.AddJavaScriptActivities());
builder.Services.AddDbContext<MvcProjContext>(options =>
Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(options,builder.Configuration.GetConnectionString("DefaultConnection")));
Or entirely call the static method without removing any usings:
using Elsa.Persistence.EntityFramework.SqlServer;
using Elsa.Persistence.EntityFramework.Core.Extensions;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddElsa(elsa => elsa
.UseEntityFrameworkPersistence(ef =>
{
DbContextOptionsBuilderExtensions.UseSqlServer(ef,builder.Configuration.GetConnectionString("DefaultConnection"));
})
.AddConsoleActivities()
.AddHttpActivities(elsaSection.GetSection("Server").Bind)
.AddJavaScriptActivities());
builder.Services.AddDbContext<MvcProjContext>(options =>
SqlServerDbContextOptionsExtensions.UseSqlServer(options,builder.Configuration.GetConnectionString("DefaultConnection")));