BigQuery.EntityFrameworkCore 0.1.3

dotnet add package BigQuery.EntityFrameworkCore --version 0.1.3
                    
NuGet\Install-Package BigQuery.EntityFrameworkCore -Version 0.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BigQuery.EntityFrameworkCore" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BigQuery.EntityFrameworkCore" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="BigQuery.EntityFrameworkCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BigQuery.EntityFrameworkCore --version 0.1.3
                    
#r "nuget: BigQuery.EntityFrameworkCore, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=BigQuery.EntityFrameworkCore&version=0.1.3
                    
Install BigQuery.EntityFrameworkCore as a Cake Addin
#tool nuget:?package=BigQuery.EntityFrameworkCore&version=0.1.3
                    
Install BigQuery.EntityFrameworkCore as a Cake Tool

EntityFramework Core to BigQuery

BigQuery.EntityFrameworkCore is C# Entity Framework Core to provide a high-level abstraction over the database for Google BigQuery.

Installation

To add BigQuery EntityFramework Core to an application, install the NuGet package for the bigquery.

Packages from NuGet:

To install or update NuGet packages, you can use the .NET Core command-line interface (CLI), the Visual Studio Package Manager Dialog, or the Visual Studio Package Manager Console.

dotnet CLI
  • Use the following .NET Core CLI command from the operating system's command line to install or update the EF Core SQL Server provider:

    dotnet add package BigQuery.EntityFrameworkCore
    dotnet add package BigQuery.EntityFrameworkCore.DependencyInjection
    
  • You can indicate a specific version in the dotnet add package command, using the -v modifier.

For more information, see .NET command-line interface (CLI) tools.

Visual Studio NuGet Package Manager Dialog
  • From the Visual Studio menu, select Project > Manage NuGet Packages

  • Click on the Browse or the Updates tab

  • To install or update the BigQuery EntityFrameworkCore provider, select the BigQuery.EntityFrameworkCore and package BigQuery.EntityFrameworkCore.DependencyInjection, and confirm.

For more information, see NuGet Package Manager Dialog.

Visual Studio NuGet Package Manager Console
  • From the Visual Studio menu, select Tools > NuGet Package Manager > Package Manager Console

  • To install or update the BigQuery EntityFrameworkCore provider, run the following command in the Package Manager Console:

    PM> Install-Package BigQuery.EntityFrameworkCore
    PM> Install-Package BigQuery.EntityFrameworkCore.DependencyInjection
    
  • To update the provider, use the Update-Package command.

For more information, see Package Manager Console.

Configuration

  • Create your table abstractions. The class name as the table name, the properties as the columns. Use if you prefer TableAttribute to specify the table name in the bigquery or ColumnAttribute to specify the column name.
    [Table("Product")]
    public class Product
    {
        public int Id { get; set; }
    
        [Column("ProductName")]
        public string Name { get; set; }
    }
    
  • Create your MyDataset class that inherit from Dataset passing as generic parameter your class to abstract the bigquery Dataset containing the table as property. Use if you prefer DatasetAttrite to specify the dataset name in the bigquery.
    [Dataset("data")]
    public class MyDataset : Dataset<MyDataset>
    {
        public Table<Product> Products { get; set; }
    }
    
  • Create your MyBqContext class that inherit from BqContext to abstract the bigquery, and add yours datasets abstractions as properties in to the MyBqContext:
    public class MyBqContext : BqContext
    {
        public MyDataset MyDataset { get; set; }
    }
    
  • In service configurations add the BigQuery EntityFrameworkCore following:
    services.AddBqContext<MyBqContext>(x =>
    {
        x.ProjectId = "your-project-id";
        x.GoogleCredential = GoogleCredential.FromJson(Configuration["your_google_auth_key"]);
    });
    

Usage

With the BqContext properly injected, we can get it in the constructor of the service, store it on a field to use it.

private readonly MyBqContext _context;

public YourService(MyBqContext context)
{
    _context = context;
}
Samples

Enumerator

_context.MyDataset.Products.ToList()
SELECT
    Product.Id,
    Product.ProductName 
FROM
    data.Product AS Product

Where

_context.MyDataset.Products.Where(x => x.Id == 1)
SELECT
    Product.Id,
    Product.ProductName 
FROM
    data.Product AS Product 
WHERE
    Product.Id = 1

Select

_context.MyDataset.Products.Select(x => x.Id)
SELECT
    Product.Id 
FROM
    data.Product AS Product

OrderBy

_context.MyDataset.Products.OrderBy(x => x.Id)
SELECT
    Product.Id,
    Product.ProductName 
FROM
    data.Product AS Product 
ORDER BY
    Product.Id

OrderByDescending

_context.MyDataset.Products.OrderByDescending(x => x.Id)
SELECT
    Product.Id,
    Product.ProductName 
FROM
    data.Product AS Product 
ORDER BY
    Product.Id DESC

Take and Skip

_context.Data.Products.Take(20).Skip(10)
SELECT
    Product.Id,
    Product.ProductName 
FROM
    data.Product AS Product LIMIT 20 OFFSET 10

Distinct

_context.Data.Products.Distinct()
SELECT
    DISTINCT Product.Id,
    Product.ProductName 
FROM
    data.Product AS Product

Join

_context.Data.Products.Join(_context.Metadata.ProductsMetadata, 
  x => x.Id, 
  x => x.Id, 
  (x, y) => new { x, y })
SELECT
    Product.Id,
    Product.ProductName,
    ProductMetadata.Id 
FROM
    data.Product AS Product 
INNER JOIN
    Metadata.ProductMetadata AS ProductMetadata 
        ON Product.Id = ProductMetadata.Id

And others old good method chain.

Author Info

linkedin: https://www.linkedin.com/in/cleber-margarida/

License

This library is under MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BigQuery.EntityFrameworkCore:

Package Downloads
BigQuery.EntityFrameworkCore.DependencyInjection

BigQuery.EntityFrameworkCore extension for Microsoft.Extensions.DependencyInjection

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.3 857 4/11/2023
0.1.2 540 4/3/2023
0.1.1 629 2/25/2023
0.1.0 595 2/23/2023