Docs / Raw SQL with MooSql

Raw SQL with MooSql

What this page covers#

This page explains the role of MooSql.

What MooSql is#

MooSql is the raw SQL execution surface for MooDb.

You do not construct it yourself. You get it from:

  • db.Sql
  • transaction.Sql

Why it exists#

MooDb is stored procedure first, but there are still valid cases for SQL text:

  • ad hoc read queries
  • direct SQL maintenance work
  • a small query that does not justify a stored procedure
  • transitional code while moving toward stored procedures

Putting SQL text on a dedicated property keeps that decision explicit.

Example#

</> C#
var users = await db.Sql.ListAsync<User>(
    "select UserId, Name from dbo.tbl_User where IsActive = 1");

Important point#

MooSql mirrors the same core query surface as MooDbContext, but uses CommandType.Text instead of CommandType.StoredProcedure.

That means the learning curve stays small.