How to restart/merge migration? - entity-framework

I'm using Entity framework code first and I have almost 10 migrations now. I found a design issue and some of the DBMigrations are not what I expected and I want to re-generated the database.
How to discard all these existed migrations and regenerate the tables on development database? (delete all the cs files under Migrations folder and delete the database? What if I want to keep the first xxxxxx_InitialCreate.cs and restart from there?)
What if the database already published to production database server? What's the best way to sync the development database/migrations and production database/migrations?

You could revert to that initial migration
Update-Database [-SourceMigration <String>] [-TargetMigration <String>]
[-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>]
[-ConfigurationTypeName <String>] -ConnectionString <String>
-ConnectionProviderName <String> [<CommonParameters>]
is the Syntax so:
Update-Database -TargetMigration InitialCreate
reverts your database to the initial migrationFor the second part I would just change the connection string to the production database and run the migration again. No loss of data should occur.

Related

PowerShell script to modify Azure data factory trigger time

I am wondering if there is any PowerShell script which can help to modify the timestamp of the existing ADF trigger. I want to change the time of my pipeline trigger in UAT as we don't have permission to do that manually from portal.
Set-AzDataFactoryV2Trigger
[-Name] <String>
[-DefinitionFile] <String>
[-ResourceGroupName] <String>
[-DataFactoryName] <String>
[-Force]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
The Set-AzDataFactoryV2Trigger cmdlet creates a trigger in a data factory. If you specify a name for a trigger that already exists, the cmdlet prompts for confirmation before replacing the trigger. If you specify the Force parameter, the cmdlet replaces the existing trigger without prompting for confirmation. Triggers are created in the 'Stopped' state, meaning that they don't immediately begin invoking pipelines that they reference.
Refer this official documentation for sample example and syntax.

Is property or field 'ServerRelativeUrl' part of the command Get-PnPFolderItem

I am getting the following error while using the command "Get-PnPFolderItem"
Get-PnPFolderItem : The property or field 'ServerRelativeUrl' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
I checked the documentation and there is no reference of it
Get-PnPFolderItem
[-FolderSiteRelativeUrl <String>]
[-ItemType <String>]
[-ItemName <String>]
[-Web <WebPipeBind>]
[-Connection <SPOnlineConnection>]
Per my test, the command "Get-PnPFolderItem" works fine on my environment. So, yes it should be part of the command Get-PnPFolderItem.
Please maek sure the version of your SharePointPnPPowerShellOnline is the lastest. Also try to connect another site and check if it works.

Entity Framework 6 and applying migration to remote database

I'm new to EF 6 and struggling how to easily apply migrations to the "remote" database. My local database is SQL Server Express and my remote database is SQL Server at GoDaddy. When I apply migrations and update the database, it appears to use the connection string from my web.config. The way I was able to apply the migration to my remote database was to swap the connection strings from my Web.Release.config and web.config files and then perform an Update-Database -TargetMigration {name of the migration}.
Are there any commands that I can use to target a specific database (without swapping the connection strings)? I've used get-help update-database but can't seem to find what I'm looking for.
Thank you
You need to apply command line switch.
Update-Database [-SourceMigration <String>] [-TargetMigration <String>] [-Script] [-Force]
[-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>]
-ConnectionString <String> -ConnectionProviderName <String>
[-AppDomainBaseDirectory <String>] [<CommonParameters>]
EF Migrations Command Reference

Why is New-SelfSignedCertificate is missing parameter -Type?

I try to sign my ps.1 file and wanted to create a code signing certificate but my New-SelfSigningCertificate does not have the parameter -Type in the function.
I use PowerShell 5.1.
When I use Get-Help, the description oddly enough also displays much less parameters than on the microsoft website. Opening the online help via Get-Help does not work because the URI is not specified.
The Help content:
SYNTAX
New-SelfSignedCertificate [-DnsName <string[]>] [-CloneCert <Certificate>]
[-CertStoreLocation <string>] [-WhatIf] [-Confirm] [<CommonParameters>]
Am I using an outdated version? Is this command only properly available in Win 10 or Server 2016?

Entity Framework 7 RC1 Reverse Engineer Entire DB only?

I have successfully reverse engineered my DB in EF7 RC1, specifically using the Package Manager Console command 'Scaffold-DbContext', as described in their documentation.
First, are there any options for reverse engineering just some of the tables in the DB? Most of my projects use only a few of the hundreds of tables in the DB.
Secondly, if we change the DB and want to reverse engineer it a second time what is the correct procedure? If I simply re-run the command it says 'Build failed' presumably because the models already exist.
are there any options for reverse engineering just some of the tables in the DB?
Yes. To see options, execute get-help Scaffold-DbContext in the Package Manager Console. This is the output for 7.0.0-rc1-final. To limit selection to only some tables, use the -Tables options
PM> get-help Scaffold-DbContext
NAME
Scaffold-DbContext
SYNOPSIS
Scaffolds a DbContext and entity type classes for a specified database.
SYNTAX
Scaffold-DbContext [-Connection] <String> [-Provider] <String> [-OutputDirectory <String>] [-ContextClassName <String>] [-Schemas <String[]>] [-Tables <String[]>] [-DataAnnotations]
[-Project <String>] [-StartupProject <String>] [-Environment <String>] [<CommonParameters>]
DESCRIPTION
Scaffolds a DbContext and entity type classes for a specified database.
RELATED LINKS
about_EntityFramework
REMARKS
To see the examples, type: "get-help Scaffold-DbContext -examples".
For more information, type: "get-help Scaffold-DbContext -detailed".
For technical information, type: "get-help Scaffold-DbContext -full".
For online help, type: "get-help Scaffold-DbContext -online"
if we change the DB and want to reverse engineer it a second time what is the correct procedure?
Delete your old model classes and context and re-run reverse engineering from the updated database. Scaffold-DbContext does not make in-place updates in RC1.
This is a a known issue with the EF7 version which will be released. Rowan Miller told this here.
You have to wait for the next large EF7 Update which will bring back some features that are missing.