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

Adjust DB context generation from DB #33131

Closed
verdysh opened this issue Feb 21, 2024 · 1 comment
Closed

Adjust DB context generation from DB #33131

verdysh opened this issue Feb 21, 2024 · 1 comment

Comments

@verdysh
Copy link

verdysh commented Feb 21, 2024

Hi,
I have EF Core of version 8.0.1 and MS SQL database. I use DB first approach so I generate DB context and entities from my DB using Scaffold-DbContext command from Visual Studio. There are few issues while generation:

  1. In my DB context I have OnConfiguring method:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
	if (!optionsBuilder.IsConfigured)
	{
		optionsBuilder.UseSqlServer("Name=ConnectionStrings:MyDb");
	}
}

This method changes and becomes as following after update:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
	=> optionsBuilder.UseSqlServer("Name=ConnectionStrings:MyDb");

But without !optionsBuilder.IsConfigured I have some exception during runtime. If necessary, I'll show exactly the error but I hope you understand what I'm talking about.

What I want: I want it doesn't remove the condition if (!optionsBuilder.IsConfigured) while updating.

  1. I have an entity class:
public partial class MyEntity
{
	...
	public MyScheduleTypeEnum ScheduleType { get; set; }
	...
}

After update MyScheduleTypeEnum becomes int.

What I want: I want to keep property type as enum.

  1. I have another entity with the following property:

public Dictionary<string, string>? Data { get; set; }

Also I have the following configuration for this property:

builder
    .Property(e => e.Data)
    .HasConversion(
        v => JsonConvert.SerializeObject(v, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }),
        v => JsonConvert.DeserializeObject<Dictionary<string, string>>(v, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })
    );

After update this property becomes string? Data instead of Dictionary<string, string>?

What I want: I want to keep property type as Dictionary<string, string>?

Now I manually restore the code above after update. But would be great if I can get rid of this manually work with each update.

Include provider and version information

EF Core version: 8.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0

@ajcvickers
Copy link
Member

Duplicate of #831. Consider using customized T4 templates for at least the first of these.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
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