Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Html;
using Newtonsoft.Json;
namespace HtmlHelpers
{
/// <summary>
@NickCraver
NickCraver / ExampleUsage.cs
Last active October 16, 2024 02:37
Code to mark a SQL string before it's passed to Dapper.
public static List<T> Query<T>(this DataContext db, string sql, object param = null, int? commandTimeout = null, IDbTransaction transaction = null, [CallerFilePath]string fromFile = null, [CallerLineNumber]int onLine = 0, string comment = null)
{
using (db.Connection.EnsureOpen())
{
try
{
return db.Connection.Query<T>(MarkSqlString(sql, fromFile, onLine, comment), param, transaction ?? db.Transaction, true, commandTimeout).AsDapperList();
}
catch (SqlException ex) when (ex.Is(SqlErrorCode.DatabaseReadOnly_3906))
{
@bricelam
bricelam / LoadEdmx.cs
Created July 16, 2014 16:14
Load an *.edmx file
MetadataWorkspace LoadEdmx(string path)
{
var runtime = XElement.Load(path).Elements().First(e => e.Name.LocalName == "Runtime");
EdmItemCollection edmCollection;
var csdl = runtime.Elements().First(e => e.Name.LocalName == "ConceptualModels")
.Elements().First(e => e.Name.LocalName == "Schema");
using (var reader = csdl.CreateReader())
{
edmCollection = new EdmItemCollection(new[] { reader });