public static T QuerySingleJson <T>(this SqlConnection cnn, string sqlFilter = "") { SqlMapper.AddTypeHandler(new JsonTypeHandler <T>()); var sql = JsonSql.Build <T>(true, false); var result = cnn.QuerySingle <T>(sql); SqlMapper.ResetTypeHandlers(); return(result); }
private static void Get(SqlConnection conn) { string select = JsonSql.Build <T>(true, forStoredProc: true); var entityName = typeof(T).Name; string sql = $@"Create or alter procedure Web.Get_{entityName} @Id Int as set nocount on; {select}"; conn.Execute(sql); }
public void SqlJsonMapper_UnderTheHoodComponentsTest() { using (var conn = new SqlConnection(connString)) { SqlMapper.AddTypeHandler(new JsonTypeHandler <Parent>()); var sql = JsonSql.Build <Parent>(true); var result = conn.QueryFirstOrDefault <Parent>(sql); result.ShouldNotBeNull(); result.Children.Count.ShouldBeGreaterThanOrEqualTo(1); SqlMapper.ResetTypeHandlers(); } }
public void ShouldReturnAString() { var result = JsonSql.Build <Parent>(true); result.ShouldNotBeNullOrEmpty(); }