Using Entity Framework Core with Spanner

The Spanner Entity Framework Core provider allows you to create a Spanner database, run queries, and update data through an application using Entity Framework Core. The provider is compatible with Microsoft.EntityFrameworkCore 3.1.

Set up the Spanner Entity Framework Core provider

To setup the Spanner Entity Framework Core provider in your application, add the following dependency.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  ...

  <ItemGroup>
    <PackageReference Include="Docker.DotNet" Version="3.125.5" />
    <PackageReference Include="Google.Cloud.EntityFrameworkCore.Spanner" Version="1.0.0" />
  </ItemGroup>

  ...

</Project>

As authentication for the Spanner Entity Framework Core provider, the service account JSON credentials file location should be provided in the GOOGLE_APPLICATION_CREDENTIALS environment variable. Otherwise, the provider can also use the default credentials set in the Google Cloud CLI gcloud application.

Use the Spanner Entity Framework Core provider

For more information about the available features, limitations of the provider, recommendations on how to use the provider, and for code samples, consult the reference documentation on GitHub.

What's next