Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infrastructure: DatabaseName is only used by tooling and shouldn't be public runtime API #7936

Closed
rigofunc opened this issue Mar 20, 2017 · 10 comments
Assignees
Labels
breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware type-bug
Milestone

Comments

@rigofunc
Copy link

rigofunc commented Mar 20, 2017

Today, I test some ef core features, I assume the test_db1 and test_db2 in the same machine:
step1: I use database named test_db1 in connection string
step2: I change the database name in OnModelCreating(ModelBuilder modelBuilder) method like this:

builder.Model.Relational().DatabaseName = "test_db2";

step3: I check where the data inserted, in test_db1? or in test_db2?

The result is data inserted into test_db1, so, my question is waht's the DatabaseName property of RelationalModelAnnotations used for?

@ajcvickers
Copy link
Contributor

@xyting The database to use is controlled only by the connection string. The DatabaseName is stored in the model as part of the reverse engineering process, but is otherwise not used.

Note for triage: Consider removing sugar API for this annotation if it is only needed by reverse engineering.

@rigofunc
Copy link
Author

@ajcvickers Thanks.

@bricelam
Copy link
Contributor

bricelam commented Apr 3, 2017

Re-opening so we can discuss @ajcvickers's comment in triage.

@bricelam bricelam reopened this Apr 3, 2017
@ajcvickers ajcvickers added this to the 2.0.0 milestone Apr 4, 2017
@lajones
Copy link
Contributor

lajones commented Apr 4, 2017

Added breaking change tag as we would be removing public API.

@ajcvickers
Copy link
Contributor

Should do this for 2.0, since it is a breaking change.

@lajones
Copy link
Contributor

lajones commented Apr 21, 2017

Fixed with PR #8247.

@lajones lajones closed this as completed Apr 21, 2017
@lajones lajones added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware labels Apr 21, 2017
@rigofunc
Copy link
Author

Good job, thanks!

@rigofunc
Copy link
Author

rigofunc commented Apr 21, 2017

@lajones Make it a Scaffolding() one instead is ok if it is only needed by reverse engineering, but, the reason why I test this feature is I want to dynamically change the database name at runtime. That's to say I want support multiple databases/tables sharding (in the same machine, I assume) in the same model. For MySQL, the Schema is the same as database, so for MySQL, I can dynamically change the the Schema to achieve the same purpose. see this implementation

@bricelam
Copy link
Contributor

bricelam commented Apr 21, 2017

@xyting Could you just use a new connection string pointing to a different database?

var newConnectionString = new SqlConnectionStringBuilder(oldConnectionString) { InitialCatalog = newDatabase }.ToString();

You may also be looking for #4019

@rigofunc
Copy link
Author

rigofunc commented Apr 21, 2017

@bricelam Yes, this is one choice. Right row, I use a DbContextFactory to dynamic create DbContext to achieve different machine multiple databases/tables sharding in the same model. In the same machine, I do not need to recreate the DbContext, I only change the MySQL Schema to archeve the database change (I doesn't study all the ef core code, so maybe I not know the Model cache whether have any performance issues if I dynamic change the MySQL EntityType's Schema).

OK, the all for test purpose, I haven't use it in my production.

@ajcvickers ajcvickers modified the milestones: 2.0.0, 2.0.0-preview1 Apr 24, 2017
@ajcvickers ajcvickers changed the title What's DatabaseName used for? Infrastructure: DatabaseName is only used by tooling and shouldn't be public runtime API May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware type-bug
Projects
None yet
Development

No branches or pull requests

5 participants