BigQuery.EntityFrameworkCore follows the Entity Framework pattern to provide a high-level abstraction over the database. It also to provide mechanisms for defining entities, mapping them to database tables, and performing CRUD operations and queries using a simplified syntax.
$ dotnet add package BigQuery.EntityFrameworkCoreBigQuery.EntityFrameworkCore is C# Entity Framework Core to provide a high-level abstraction over the database for Google BigQuery.
To add BigQuery EntityFramework Core to an application, install the NuGet package for the bigquery.
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.
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.
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.
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.
[Table("Product")]
public class Product
{
public int Id { get; set; }
[Column("ProductName")]
public string Name { get; set; }
}
[Dataset("data")]
public class MyDataset : Dataset<MyDataset>
{
public Table<Product> Products { get; set; }
}
public class MyBqContext : BqContext
{
public MyDataset MyDataset { get; set; }
}
services.AddBqContext<MyBqContext>(x =>
{
x.ProjectId = "your-project-id";
x.GoogleCredential = GoogleCredential.FromJson(Configuration["your_google_auth_key"]);
});
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;
}
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.
linkedin: https://www.linkedin.com/in/cleber-margarida/
This library is under MIT License.