Comments (8)
I am having some difficulties understanding the use case here.
Could you create a unit test to somehow help you?
from efcorepowertools.
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.
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.
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.
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.
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.
There is no simple way of doing that. It is not something I plan to implement
from efcorepowertools.
I can appreciate that. Thanks anyway and keep up the great work!
from efcorepowertools.
Related Issues (20)
- Duplicated configuration classes when using EntityTypeConfiguration.t4 HOT 10
- can't install on Microsoft Visual Studio Enterprise 2022 (ARM 64-bit) - Current Version 17.9.5 HOT 4
- SQL Server procedures - named parameters HOT 3
- Table Renaming is not working (or im doing wrong?) HOT 6
- #nullable -annotations not set for procedures HOT 9
- Unable to get result set shape for dbo.SP_* HOT 2
- Project table relationships are not generating correctly HOT 1
- Stored Procedures stopped working in new version HOT 5
- Is the Entity Id navigation property name convention changed? HOT 18
- Add Server Explorer launch button to localized VS versions
- Add an option to strip a prefix from Model names during Reverse Engineering HOT 2
- Add Visualize DB Schema context menu to Server Explorer
- SqlLite computed columns HOT 5
- Oracle Data source not listed HOT 5
- Add help link on Data Source screen
- Unable to install VSIX for ARM64 HOT 21
- Code error in DbContextExtensions.Sync.cs HOT 5
- How to add Metadata to identity column when create dbcontext HOT 2
- *Procedures.cs missing OnModelCreatingGeneratedProcedures method HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcorepowertools.