Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 1.14 KB

21-sobreescrevendo-comportamentos-efcore.md

File metadata and controls

41 lines (32 loc) · 1.14 KB

Sobreescrevendo comportamentos do EF Core

optionsBuilder
    .LogTo(Console.WriteLine)
    .UseSqlServer("Server=localhost, 1433;Database=DominandoEFCore;User Id=sa;Password=!123Senha;")
    .EnableSensitiveDataLogging()
    .ReplaceService<IQuerySqlGeneratorFactory, MySqlServerQuerySqlGeneratorFactory>();


public class MySqlServerQueryGenerator : SqlServerQuerySqlGenerator
{
    public MySqlServerQueryGenerator(QuerySqlGeneratorDependencies dependencies) : base(dependencies)
    {
        
    }

    protected override Expression VisitTable(TableExpression tableExpression)
    {
        var table = base.VisitTable(tableExpression);
        Sql.Append(" WITH (NOLOCK)");
        return table;
    }
}

public class MySqlServerQuerySqlGeneratorFactory : SqlServerQuerySqlGeneratorFactory
{
    private readonly QuerySqlGeneratorDependencies _dependencies;
    
    public MySqlServerQuerySqlGeneratorFactory(QuerySqlGeneratorDependencies dependencies) : base(dependencies)
    {
        _dependencies = dependencies;
    }

    public override QuerySqlGenerator Create()
    {
        return new MySqlServerQueryGenerator(_dependencies);
    }
}