-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Describe the bug
AddDataContextSQL provides optional param to extend SQL dbContext like using NetToplogySutie
However it leads to fail to connect to db using correct connection string
To Reproduce
Steps to reproduce the behavior:
- Init ApiGenerator like this:
builder.Services.AddApiGeneratorServices()
.AddAssemblyWithOData(Assembly.GetExecutingAssembly())
.AddDataContextSQL( x=> x.UseNetTopologySuite())
.AddOData()
.AddSwagger(true);
- Open swagger to test GET API
- HTTP 500 ERROR will be returned
---> System.InvalidOperationException: A relational store has been configured without specifying either the DbConnection or connection string to use.
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
Expected behavior
200 OK and data should be returned correctly
Desktop (please complete the following information):
- OS: Windows 11
- Browser Edge
- Version 122.0.2365.80 / 64bit
Additional context
- Workaround: Register GenericDbContext using AddDbContext and UseSqlServer directly before call AddDataContextSQL
// Add API Generator and load data
var api_generator = builder.Services.AddApiGeneratorServices()
.AddAssemblyWithOData(Assembly.GetExecutingAssembly());
api_generator.Services.AddDbContext<GenericDbContext>(options => options.UseSqlServer(
myconnectionstring,
x => x.UseNetTopologySuite()).EnableSensitiveDataLogging()
.LogTo(Console.WriteLine, LogLevel.Information));
api_generator.AddDataContextSQL()
.AddOData()
.AddSwagger(true);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels