GenerateFluentConfig

 

This will generate a DBcontext file as well as separate Fluent configuration 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 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.


Was this article helpful?