Skip to content

olsh/sql-analyzer-net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Analyzer

Build status Quality Gate Status codecov

A Roslyn-based analyzer for SQL related stuff in .NET

Analyzers

SQL001: SQL type is not specified

Noncompliant Code Example:

Query<Thing>("select * from Thing where Name = @Name", new { Name = abcde });

Compliant Solution:

Query<Thing>("select * from Thing where Name = @Name", new {Name = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = true }});

https://github.com/StackExchange/Dapper/blob/master/Readme.md#ansi-strings-and-varchar

SQL002: SQL parameters mismatch

Noncompliant Code Example:

var dog = connection.Query<Dog>("select Age = @Age, Id = @Id", new { Id = guid });

Compliant Solution:

var dog = connection.Query<Dog>("select Age = @Age, Id = @Id", new { Age = (int?)null, Id = guid });

SQL003: Using 'Query' method is not optimal here

Noncompliant Code Example:

var dog = connection.Query<Dog>("select * from dogs").Single();

Compliant Solution:

var dog = connection.QuerySingle<Dog>("select * from dogs");

https://github.com/StackExchange/Dapper#performance

About

Roslyn-based analyzer for SQL related stuff in .NET

Topics

Resources

License

Stars

Watchers

Forks

Languages