Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for adding Aspire SQL Server? #887

Open
mikeleigh1010 opened this issue Nov 27, 2024 · 7 comments
Open

Support for adding Aspire SQL Server? #887

mikeleigh1010 opened this issue Nov 27, 2024 · 7 comments
Assignees
Labels

Comments

@mikeleigh1010
Copy link

It would be helpful if the project could either document or support swapping out from using sql lite to using an aspire configured instance of SQL server.

  • .NET SDK Version: 9

Steps to Reproduce:

1.Add configuration for a sql server reference
2.Update reference from UseSqlLite to AddSqlServerDbContext

@ardalis
Copy link
Owner

ardalis commented Dec 3, 2024

Agreed 100%

@ardalis ardalis added enhancement help wanted good first issue .NET Pull requests that update .net code labels Dec 3, 2024
@benjaminmishra
Copy link
Contributor

@ardalis - I can give this one a try. I have some ideas around how this can be done.

@ardalis
Copy link
Owner

ardalis commented Dec 10, 2024

All yours.
You might look at this related issue:
ardalis/DotNetDataAccessTour#8

@ardalis
Copy link
Owner

ardalis commented Dec 20, 2024

@benjaminmishra any update?

@benjaminmishra
Copy link
Contributor

@ardalis yes, figured out that it can be done using preprocessor directive like syntax
So we can have the following line of code in the InfrastructureServiceExtensions.cs file.

#if (UseSqlServer)
  services.AddDbContext<AppDbContext>(options => options.UseSqlServer(connectionString));
#else
  services.AddDbContext<AppDbContext>(options => options.UseSqlite(connectionString));
#endif

Question: How do we want to expose this as an option ? I was thinking may be we can add some flags while template creation and let the user choose the database type they want to use based on this flag?

choice parameter

@ardalis
Copy link
Owner

ardalis commented Dec 22, 2024

Yes, exactly. A flag during template creation.

@mikeleigh1010
Copy link
Author

mikeleigh1010 commented Dec 24, 2024

Might be also worth considering if the project should maintain the recommended approach for running migrations with Aspire

https://learn.microsoft.com/en-us/dotnet/aspire/database/ef-core-migrations

This approach makes use of having the migrations ran from a worker service, this way the connection string can be passed in, and the service can run to completion I believe,

So, we could have this worker service migrator project be optionally created with the --aspire flag? but then seems superfluous as no all projects using aspire will require to run migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants