msawczyn / EFDesigner2022

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
MIT License
119 stars 21 forks source link

When creating an Independent EFModel Class library/Project, its missing settings in context & EF core migrations fail. #43

Closed fasteddys closed 1 year ago

fasteddys commented 1 year ago

Been reading your docs a lot!! :)

I created an independent class lib in EF 6 (to keep this as clean as possible), and refer to the models from other projects.


image this picture shows me, that I failed to add migrations. I assume its because there is a missing connectionstringin the DBcontext

image

Question 1: How do I get the EF designer 2k22 code gen to pick up the connection string?, so it can be scaffolded into the DBcontext. And, where does it pick it up from, I even tried to add a app.config file with a new connection string, but its not picking it up... should I be doing this differently?

<?xml version="1.0" encoding="utf-8" ?>

Question 2: From the model generated, to create a new database -> am I correct in creating a new migration, using that I would create my Database? or how do I create the DB from the EF Designer Models?

msawczyn commented 1 year ago

1) You can add the connection string as a property of the designer surface. image Click the design surface and these will appear in the property window. Note you can add either a connection string or a connection string name (with the connection string being stored in a config file somewhere else) and EFCore will be able to use it.

2) Generating the model gets you the entity classes and a DbContext -- from there you can create the migrations, use the context, etc. The EFCore docs talk about how the migrations can automatically create a database, how to update that structure, etc.

fasteddys commented 1 year ago

thanks