Hi @Wadiwala, Rohan ,Welcome to Microsoft Q&A.
You have several ways to achieve your needs.
One way is to use Entity Framework Core to execute your sql script.
Install the correct nuget package
- Create a DbContext class that inherits from . This class will represent the application's data model and provide methods for interacting with the database. Here is an example:
DbContext
using Microsoft. EntityFrameworkCore;
public class YourDbContext : DbContext
{
public DbSet<YourEntity> YourEntities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("your_connection_string_here");
}
}
Use ExecuteSqlRaw to execute your sql statement.
public void CreateDatabase()
{
using (var context = new YourDbContext())
{
context.Database.ExecuteSqlRaw("your_sql_script_here");
}
}
You can of course directly open localsqlserver to create your database.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.