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

Probable bug to the integrate two or more DbContext #7455

Closed
ghost opened this issue Jan 23, 2017 · 1 comment
Closed

Probable bug to the integrate two or more DbContext #7455

ghost opened this issue Jan 23, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 23, 2017

I work with Domain Driven Design concept and i am having on problem to integrate two DbContexts. Apparently is a bug, but i want friends' opinion.

I have two domains. In each one of domains exists one class with the same name "city". This class refers to same table in the database, but in one context is important only some properties and in other context, others properties. This is motive of have two class "City" in two context pointing out to same table, all configurated through of Mapping of contexts (https://docs.microsoft.com/en-us/ef/core/modeling/relational/tables)

I am working with native Dependency Injection of Asp Net Core. Create one project "MyProject.Infra.CrossCutting.IoC" of CrossCutting only to configure and inject the dependency. In this project contains only one static class with one static function to receive with parameter an IServiceCollection to configure my dependency injection.

In Asp Net Core project, have ConfigureServices function. Is In this function that I call my static class and pass how parameter the IServiceCollection.

NOW IS THE PROBLEM!! When i running entity framework core migration of the Domain 1 is create table City, but when i running migration of the Domain 2, I receive the message of output console saying that the City Table already exists. Migration can not understand the changes writes in MigrationHistory of the Domain 1.

Basically, what i want is integrate two or more context insomuch that migration understand through of Mapping of Contexts that the classes City of Context 1 and Context 2 mold my City Table

Further technical details

EF Core version: 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 1.1.0
Operating system: Windows 10 Version 10.0.14393
IDE: Visual Studio 2017 RC Version 4.6.01586

@rowanmiller
Copy link
Contributor

This is essentially a duplicate of #2725. Migrations doesn't reason about other models, what's already in the database, etc. It is purely about creating/altering the schema for a given model.

The easiest way to handle this now, is to just delete the CreateTable call for the City table when you scaffold the migration for Domain 2.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants