Wednesday, July 17, 2024

EF Core 8.0: Numeric Rowversion for Azure SQL/Microsoft SQL Server

In this post, let's have a look at this small yet handy EF Core 8.0 feature for troubleshooting concurrency issues.

Before EF Core 8.0, the rowversion property in C# classes needs to be of type byte[].
public record Post
    public int Id { getset}

    public string Title { getset}

    public byte[] Timestamp { getset}
And when debugging, it looks like the following.
Timestamp as byte[]
Now with EF Core 8.0, we can map the rowversion to long or ulong.
protected override void OnModelCreating(ModelBuilder modelBuilder)
        .Property(e => e.Timestamp)
public record Post
    public int Id { getset}

    public string Title { getset}

    public long Timestamp { getset}
When debugging it's more readable now.
Timestamp as long
Happy Coding.


Monday, July 15, 2024

Introducing dotnet nuget why

With .NET SDK 8.0.4xx and later versions, we will have access to a   new dotnet nuget command: dotnet nuget why. You can try this now with the latest .NET 9 SDK Preview: 9.0.100-preview.6 (thanks @ErikEJ for pointing it out).
dotnet nuget why --help
dotnet nuget why --help
For an example,
dotnet nuget why <PROJECT|SOLUTION> System.Text.Json
dotnet nuget why
I can see the dependency graph for the given package and if it references an old package.

Read more:

Happy Coding.


Thursday, July 11, 2024

Received Microsoft MVP Award in Developer Technologies

I am humbled and honored once again to receive the precious Microsoft Most Valuable Professional (MVP) Award for the 11th consecutive year.

As always looking forward to another great year on top of Microsoft Development Stack.
Microsoft Most Valuable Professional (MVP)
Thank you Microsoft for your appreciation and Thank you everyone for your continuous support.

Happy Coding.


Tuesday, July 2, 2024

Azure DevOps Pipeline: Build and Deploy Azure Container App

In this post, let's see how we can build and deploy an Azure Container App from an Azure DevOps Pipeline.

Here for deployment, I am using az containerapp update.

      - main

  vmImage: ubuntu-latest

  acrServiceConnection: <ACR_SERVICE_CONNECTION>
  imageRepositoryName: '<ACR_REPOSITORY_NAME>'
  containerAppServiceConnection: '<CONTAINER_APP_SERVICE_CONNECTION>'
  containerAppResourceGroup: '<CONTAINER_APP_RESOURCE_GROUP>'
  containerAppName: '<CONTAINER_APP_NAME>'

name: $(Build.BuildId)

stage: Build
  displayName: Build
  - job: Build
    displayName: Build Docker Image
    - task: Docker@2
      displayName: Build and push an image to container registry
        containerRegistry: '$(acrServiceConnection)'
        repository: '$(imageRepositoryName)'
        command: 'buildAndPush'
        Dockerfile: '**/Dockerfile'
        buildContext: './'
        tags: '$(Build.BuildId)'

stage: Deploy
  displayName: Deploy
  - Build
  condition: succeeded('Build')
  - deployment: Deployment
    displayName: Deploy to Container App
    # Requires an environment named 'Development'
    environment: Development
           - task: AzureCLI@2
             displayName: Update Container App
               azureSubscription: '$(containerAppServiceConnection)'
               scriptType: 'bash'
               scriptLocation: 'inlineScript'
               inlineScript: |
                 az containerapp update \
                 --name $(containerAppName) \
                 --resource-group $(containerAppResourceGroup) \
                 --image '$(acrName)/$(imageRepositoryName):$(Build.BuildId)' \
                 --set-env-vars \
                   'MongoDB__ConnectionString=<VALUE>' \
                   'ServiceBus__ConnectionString=<VALUE>' \
                 --min-replicas 1 \
                 --max-replicas 1

Azure DevOps already has an Azure Container Apps Deployment Task AzureContainerApps@1, which I haven't used, but do check it out.

Hope this helps.

Happy Coding.