3

Feel free to tell me that this question needs to be moved and I will move it. I just don't know where else to go for help.

My current work flow is:

  1. Create the database first (database Actual)
  2. Run scaffold command which creates my models
  3. Create a Visual Studio Database project
  4. Import the database (database project)

Whenever I need to make a change to the database I follow the below:

  1. Change the database project
  2. Run a Schema Compare
  3. Verify and update the database Actual
  4. rerun the scaffold command with a -Force to rebuild all the models.

What (if any) type of problems am I leaving myself open to down the road?

I am not seeing the value of database migrations as I am updating the database first but using the database project to provide source control and some protection.

I always used to use the graphic database tool, but obviously with Core that is no longer an option.

I have also considered Devart's Entity Developer as a ORM.

Your thoughts and feedback are VERY much appreciated.

So the biggest problem is what happens when I need to make changes to the model.

So something simple like:

 public partial class UserInfo
{
    public int Id { get; set; }
    [Required]
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public DateTime RecordCreated { get; set; }
}

My '[Required]' will obliviously be gone after a -force.

Joe

Joe Ruder
  • 2,122
  • 2
  • 23
  • 52

1 Answers1

3

That is the correct "database first" workflow for EF Core, and you would not use migrations in that scenario. Be sure to place customizations to your entities or DbContext in separate partial class files so they don't get clobbered when you regenerate the entities.

always used to use the graphic database tool, but obviously with Core that is no longer an option.

With this workflow you can use any graphical design tool you want for your database schema.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • Do you mean for instance if I add [Required] or other validation in the model class? I was wondering about that. How would I do that? If you could just point me at something that would be helpful. I will update my question as well. – Joe Ruder Dec 01 '18 at 19:29
  • This answered my question. I will post the additional part as a new question. Thank you. – Joe Ruder Dec 01 '18 at 20:05
  • David Browne, I am still trying to figure out HOW to do the partial class. It sounds easy in theory but I just can't get it working. I have a open question here: https://stackoverflow.com/questions/53574640/add-modifications-to-your-model-when-using-ef-core-db-first-design – Joe Ruder Dec 01 '18 at 22:14