Extensions

In this section we will tap into the extensibility points of the Jerrycurl engine by looking at two offical extensions that provide JSON support and integration with existing Entity Framework Core projects.

JSON

If wanting to support JSON in your project you first have to pick you favorite serializer. We provide two packages for enabling JSON: one for the popular Newtonsoft.Json serializer and another for the new, .NET Standard 2.1-native System.Text.Json serializer.

Either of these can be easily installed from NuGet. For our project we rely on System.Text.Json.

>
dotnet add package Jerrycurl.Extensions.Json

This gives us the UseJson extension method that we call to add JSON-based type mappers to our domain.

1
2
3
4
5
6
7
8
public class JerryDomain : IDomain
{
    public void Configure(DomainOptions options)
    {
        // connection setup
        options.UseJson();
    }
}

After this we can start designing our JSON model. Say for example that we want to add an ExtraInfo JSON column to the Customer table.

First we would declare a CustomerInfo class and add the Json attribute to have it recognized by the type mapper.

1
2
3
4
5
6
[Json]
public class CustomerInfo
{
    public int Age { get; set; }
    public int Height { get; set; }
}

Next, we would write either a query or a command that uses this type as either a parameter value

1
2
3
4
5
6
7
@model CustomerInfo
@project Customer c

UPDATE
    @c.TblName()
SET
    @c.Col(m => m.ExtraInfo) = @M.Par()

or a query target

1
2
3
4
5
6
7
@result CustomerInfo
@project Customer c

SELECT
    @c.Col(m => m.ExtraInfo) AS @R.Prop()
FROM
    @c.Tbl()

Entity Framework Core

If you have an existing project using EF Core as your ORM, you can use Jerrycurl in combination to this framework by installing the EF Core integration package.

This package allows you to inject metadata from an EF Core DbContext, so you to reuse the model you are using to query your database via LINQ. As usualy, it's set up through a single extension method.

1
2
3
4
5
6
7
8
public class MyDomain : IDomain
{
    public void Configure(DomainOptions options)
    {
        // connection setup
        options.UseEntityFrameworkCore<SomeDbContext>();
    }
}
Note that we only integrate metadata from EF and do not subscribe to its change-tracking behavior, connection setup or any other configuration.