GithubHelp home page GithubHelp logo

Comments (8)

ErikEJ avatar ErikEJ commented on June 19, 2024

I am having some difficulties understanding the use case here.

Could you create a unit test to somehow help you?

from efcorepowertools.

jscarle avatar jscarle commented on June 19, 2024

I often do migrations of legacy systems where I start developing new code on top of the same database that is being used by an older system.

If I scaffold such a database, I'll often end up with something that looks like this:

public class ProductConfiguration : IEntityTypeConfiguration<Product>
{
    public int ProductId { get; set; }
    public DateTime Created { get; set; }
    public DateTime Updated { get; set; }
    public string ProductName { get; set; } = "";
    public string Description { get; set; } = "";

    public void Configure(EntityTypeBuilder<Product> entity)
    {
        entity.HasKey(e => e.ProductId);

        entity.ToTable("Products");

        entity.Property(e => e.ProductId).HasColumnName("ProductID");
        entity.Property(e => e.ProductName).HasMaxLength(255);
    }
}

As you can see, there is no .HasColumnName() if there is no difference between the underlying database name and the property name. If I were to rename the property ProductName to simply Name in my entity, EF will then generate a migration to rename that column (which I do not want). Thus, the only way to prevent that is to go through ALL of my entity configurations and manually add a .HasColumnName() to every single one of my properties, which as you can imagine takes hours.

from efcorepowertools.

ErikEJ avatar ErikEJ commented on June 19, 2024

So you are switching from reverse engineering to migrations ???

This is not very well supported, as scaffolding omits a lot of conventional model properties.

I will investigate.

from efcorepowertools.

jscarle avatar jscarle commented on June 19, 2024

Yes, it's a very common scenario when migrating legacy systems. .HasColumnName() is a really good starting point because you can later on adjust your models for more specific properties such as precision as you develop against a test database, but at least you prevent the catastrophic breaking of column names which can make stored procedures completely explode.

from efcorepowertools.

ErikEJ avatar ErikEJ commented on June 19, 2024

Iterate the DbContext model and persists a file with an ordered list (schema,table,column) - call it "baseline"

Add a test that compares the baseline with your current model to detect drift.

from efcorepowertools.

jscarle avatar jscarle commented on June 19, 2024

That's an interesting approach. I'll take a look at how I could write that unit test efficiently. Though it still doesn't address my initial request. 🙃

from efcorepowertools.

ErikEJ avatar ErikEJ commented on June 19, 2024

There is no simple way of doing that. It is not something I plan to implement

from efcorepowertools.

jscarle avatar jscarle commented on June 19, 2024

I can appreciate that. Thanks anyway and keep up the great work!

from efcorepowertools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.