Closed LeopoldLerch closed 2 years ago
Limited rights to the database?
I probably need a repro project.
No, it is the same database, tried even with the same connectionstring (with user/password authentication)
When simply commenting out
DbConfiguration.SetConfiguration(new MicrosoftSqlDbConfiguration())
the table is set up with correct defaults. When deleting the migration from history and the tables, remove the comment from the config above and rerunning it, the table is created also, but the defaults are not set.
Not limited to one table, i have 2 tables with the same issue.
I need a simple repro.
Will a Model help, from which you then can generate a migration for your database?
Sure, an console app with just the model.
You will need to insert your own connectionString of course. When commenting in the DBConfiguration-Line, the Defaults for the DateTime-Columns are not set. When commented out, they are correct.
Thanks
Okay,
seems to have something todo with
SetSqlGenerator("System.Data.SqlClient", new DefaultValueSqlServerMigrationSqlGenerator());
in Configuration.cs of my example.
If i Change that to "Microsoft.Data.SqlClient", it seems to work.
However, I have the DatabaseModel separated in a libary, as it is used by more projects. And only one of them is using your package as it is the only one on .Net Core. So I cannot change this value for all of them. Is there any way to get that part somehow flexible?
Sure, create a seperate .csproj/package and use conditional compilation.
@LeopoldLerch Pretty sure, as it is just a string value, you can register both and it will pickup based on the provider in use.
SetSqlGenerator("System.Data.SqlClient", new DefaultValueSqlServerMigrationSqlGenerator());
SetSqlGenerator("Microsoft.Data.SqlClient", new DefaultValueSqlServerMigrationSqlGenerator());
I have something very similar to the DefaultValueSqlServerMigrationSqlGenerator
in my own code, although I have extension methods in the same library that sets up my DbMigrationsConfiguration and DBContexts which I call in the constructors.
This means that I should be able to just add the line to my extension method and all my libraries will be enabled for both providers.
Sure that i can Register both? Dont they Override each other?
Will try in monday. Thx
Cynthia MacLeod @.***> schrieb am Fr., 1. Okt. 2021, 17:47:
@LeopoldLerch https://github.com/LeopoldLerch Pretty sure, as it is just a string value, you can register both and it will pickup based on the provider in use.
SetSqlGenerator("System.Data.SqlClient", new DefaultValueSqlServerMigrationSqlGenerator());SetSqlGenerator("Microsoft.Data.SqlClient", new DefaultValueSqlServerMigrationSqlGenerator());
I have something very similar to the DefaultValueSqlServerMigrationSqlGenerator in my own code, although I have extension methods in the same library that sets up my DbMigrationsConfiguration and DBContexts which I call in the constructors. This means that I should be able to just add the line to my extension method and all my libraries will be enabled for both providers.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ErikEJ/EntityFramework6PowerTools/issues/87#issuecomment-932344208, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4MXZZA6O6TS7LCSUYXHK3UEXJYJANCNFSM5FEU4F5A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Hi, I am using EF6 in Code-First. I have the strange problem, that obviously defaults are not set in tables when the migration is applied using your Nuget-Package ErikEJ.EntityFramework.SqlServer.
I use it by setting DbConfiguration.SetConfiguration(new MicrosoftSqlDbConfiguration()); in the configure-Method in Startup. Authorization etc works fine (i am using Azure integrated authentication)
When checking the create-Statements of the created tables for example the following is missing:
When creating the same table using another project which is not using your nuget-package (or removing it in the very same project), this line is there (and the defaults are applied).
The Migration-Code which should be applied looks like that:
CreateTable( "dbo.MLRegistration", c => new { UserName = c.String(nullable: false, maxLength: 128), Disabled = c.Boolean(nullable: false), RegistrationTime = c.DateTime(nullable: false, annotations: new Dictionary<string, AnnotationValues> { { "SqlDefaultValue", new AnnotationValues(oldValue: null, newValue: "getdate()") }, }), }) .PrimaryKey(t => t.UserName);
Maybe you can help me?