How does EF know what database to use?
Hello there.
I am building an entity related management system, and I'm wondering how EF know what database I want it to use. I am using .Net 8, and the only place I have referenced the database was in the Program.cs file, however, I have commented out that part and it is still able to update my database. How is that possible?
7 Replies
EF uses the connectionstring you have given, either in the context itself or via the context options object, often configured via Program.cs
if you show your code, Im sure we can find where its reading the connstr from
My DBContext:
Program.cs:
at some point, the program.cs code was not out-commented, so i wonder if it saved a copy of the connection string somewhere
uh
if you comment out all of program.cs, your program wont compile and run
so its using the old built version
thats my guess at least
ie, its still using the old version that had all of program.cs
its built like a console app, however, it's used as a library for another project in my solution if that makes sense
dont do that
build it as a library if its a library
and then you'd let the consuming app worry about the settings/connstr
im building a function app for azure, so would it make sense to move all my library stuff to the function app project?
¯\_(ツ)_/¯
Dunno
Have never built azure functions for anything other than small snippets