GenerateFluentConfig

<< >>

Navigation:  CodeStencil > Custom Library > Code Nanites > Table Related >

GenerateFluentConfig

Expansion Label:

CS_GENERATE_FLUENT_CONFIG

Dependency:


Description:

Generate Fluent API ModelBuilder Config.

 

This will generate a dbcontext file as well as seperate Fluent configuiration files    

This is what setting up this Code Nanite looks like:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace [%NAMESPACE%].Domain.Models.EntityConfiguration
{
    public class [%CS_CURRENT_TABLE%]Configuration
    {
        public [%CS_CURRENT_TABLE%]Configuration(EntityTypeBuilder<[%CS_CURRENT_TABLE%]> entity)
        {
[%CS_GENERATE_FLUENT_CONFIG%]
        }
    }
}

 

This is what the generated code looks like:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace ZeraSystems.BlazorGrid.Domain.Models.EntityConfiguration
{
    public class ArtistConfiguration
    {
        public ArtistConfiguration(EntityTypeBuilder<Artist> entity)
        {
        entity.ToTable("Artist")
            .HasKey(e => e.ArtistId);
        entity.Property(e => e.ArtistId)
            .HasColumnName("ArtistId")
            .HasColumnType("int");
        entity.Property(e => e.Name)
            .HasColumnName("Name")
            .HasColumnType("string")
            .HasMaxLength(120);
        }
    }
}

The highlighted the code is what is generated and inserted by the  CS_GENERATE_FLUENT_CONFIG code nanite. Also, it generates code for every table in your schema because in the label of the node ( See Code Tree), we used the [%CS_TABLE_LIST%] Code Nanite.