Ask Your Question
2

What is the process for indicating the name of a database using Code First?

asked 2023-05-27 07:45:20 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-27 08:00:01 +0000

devzero gravatar image

To indicate the name of a database using Code First, you can use the DbContext class and override the OnModelCreating method. Within this method, you can use the modelBuilder parameter to specify the name of the database by calling the HasDatabaseName method.

Example:

public class MyDbContext : DbContext
{
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasDatabaseName("MyDatabaseName");
    }
}

This will set the name of your database to "MyDatabaseName".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-27 07:45:20 +0000

Seen: 17 times

Last updated: May 27 '23