Skip to content

Instantly share code, notes, and snippets.

@mirmostafa
Last active June 8, 2026 14:10
Show Gist options
  • Select an option

  • Save mirmostafa/04361c074ec397ebc3476bee21ce4a3a to your computer and use it in GitHub Desktop.

Select an option

Save mirmostafa/04361c074ec397ebc3476bee21ce4a3a to your computer and use it in GitHub Desktop.
From SQL Interpolated String
var dbResult = await this._readDbContext.ProductCategories.FromSqlInterpolated($@"
SELECT TOP 1 *
FROM [biz].[ProductCategories] t
WHERE NOT EXISTS (SELECT 1
FROM [biz].[ProductCategories]
WHERE ParentProductCategoryId = t.ProductCategoryId)
AND t.ProductCategoryId = {parameters.CategoryId} AND MerchantId = {merchantId}")
.AsNoTracking().FirstOrDefaultAsync();
@mirmostafa

Copy link
Copy Markdown
Author

As SQL parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment