Invalid object name 'Elsa.WorkflowInstances'.
See original GitHub issueI’m getting the same error as issue #2930 in both .NET 6 and .NET 7, on latest Elsa as well as the RC. I’ve told it to run migrations at runtime as well as through the dotnet ef tooling according to this guide in the docs. Both ways result in an empty database. There is an __EFMigrationHistory table, but it’s empty.
Could this be environmental? I recently switch from a Windows 10 VM to a Windows Server VM for developing the application I’m having issues with. I otherwise don’t know what would be wrong on my end.
For completeness, here’s the example program I put together from both a blank .NET 6 and .NET 7 web API project. The appsettings.json file contains the appropriate “Elsa” section as well as a connection string.
using Elsa;
using Elsa.Activities.Console;
using Elsa.Activities.Temporal;
using Elsa.Builders;
using Elsa.Persistence.EntityFramework.Core;
using Elsa.Persistence.EntityFramework.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using NodaTime;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var elsaSection = builder.Configuration.GetSection("Elsa");
// Elsa services.
builder.Services
.AddElsa(elsa => elsa
.UseEntityFrameworkPersistence(ef => ef.UseSqlServer(builder.Configuration.GetConnectionString("Elsa")!), autoRunMigrations: true)
.AddConsoleActivities()
.AddHttpActivities(elsaSection.GetSection("Server").Bind)
.AddQuartzTemporalActivities()
.AddJavaScriptActivities()
.AddWorkflowsFrom<Program>()
);
// Elsa API endpoints.
builder.Services.AddElsaApiEndpoints();
// Allow arbitrary client browser apps to access the API.
// In a production environment, make sure to allow only origins you trust.
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
.WithExposedHeaders("Content-Disposition"))
);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app
.UseCors()
.UseHttpActivities()
.UseRouting()
.UseEndpoints(endpoints =>
{
// Elsa API Endpoints are implemented as regular ASP.NET Core API controllers.
endpoints.MapControllers();
});
app.UseHttpsRedirection();
app.Run();
public class HeartbeatWorkflow : IWorkflow
{
private readonly IClock _clock;
public HeartbeatWorkflow(IClock clock) => _clock = clock;
public void Build(IWorkflowBuilder builder) =>
builder
.Timer(Duration.FromSeconds(10))
.WriteLine(context => $"Heartbeat at {_clock.GetCurrentInstant()}");
}
public class SqlElsaContextFactory : IDesignTimeDbContextFactory<ElsaContext>
{
public ElsaContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddCommandLine(args)
.Build();
var dbContextBuilder = new DbContextOptionsBuilder();
var connectionString = configuration.GetConnectionString("Elsa");
dbContextBuilder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(typeof(Program).Assembly.FullName));
return new ElsaContext(dbContextBuilder.Options);
}
}
Issue Analytics
- State:
- Created 9 months ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
how to use sqlServer in Sample19? · Issue #174 · elsa- ...
I am getting an issue like Microsoft.Data.SqlClient.SqlException: 'Invalid object name 'Elsa.Workflow Instances while trying to connect with the ...
Read more >Elsa Workflows: Use SQL Server with Entity Framework Core
I'm struggling following the basic tutorial for Elsa with Ef-Core/SQL persistence. At runtime, the application fails with error clearly ...
Read more >Elsa Persistence Providers
Elsa has abstracted away its data access logic, enabling the persistence layer to ... public void ConfigureServices(IServiceCollection services) { services.
Read more >Working with Workflow Contexts · ELSA
A workflow context represents a model that is specific to your own domain, which means it can be any object that you like....
Read more >What's new in Elsa 2.0
Composite Activities are a new class of custom activities that you can write using the Workflow Builder API. Example: public class AskNameActivity : ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for sharing @bogdandynamic ! Indeed, the extension names are the same, which makes it very subtle to identify the issue. For V3, we changed the extension names to avoid confusion.
I was stuck with the same problem but ultimately managed to figure it out. Just remove the
using Microsoft.EntityFrameworkCore;
import and addusing Elsa.Persistence.EntityFramework.SqlServer;
. Your code (and mine also) was using theUseSqlServer
extension method from the Microsoft.EntityFrameworkCore assembly and not from Elsa.Persistence.EntityFramework.SqlServer. After the switch, all worked flawlessly. Hope it helps.