Исходный код вики Сценарии
Версия 1.2 от Alexandr Fokin на 2023/10/31 19:41
Скрыть последних авторов
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | | |Can JSONB GIN indexes be specified in CodeFirst EntityFramework with NPGSQL? |
| 2 | [[https:~~/~~/stackoverflow.com/questions/54618858/can-jsonb-gin-indexes-be-specified-in-codefirst-entityframework-with-npgsql>>https://stackoverflow.com/questions/54618858/can-jsonb-gin-indexes-be-specified-in-codefirst-entityframework-with-npgsql]] | ||
| |
1.2 | 3 | |Parameters|{{code language="c#"}}public static class QueryParameterExtensions |
| 4 | { | ||
| 5 | public static NpgsqlParameter StructToDbParameter<T>( | ||
| 6 | this T value, | ||
| 7 | string name, | ||
| 8 | NpgsqlDbType type | ||
| 9 | ) | ||
| 10 | where T : struct | ||
| 11 | { | ||
| 12 | return new NpgsqlParameter<T>(name, type) { TypedValue = value }; | ||
| 13 | } | ||
| 14 | |||
| 15 | public static NpgsqlParameter StructToDbParameter<T>( | ||
| 16 | this T? value, | ||
| 17 | string name, | ||
| 18 | NpgsqlDbType type | ||
| 19 | ) | ||
| 20 | where T : struct | ||
| 21 | { | ||
| 22 | if (!value.HasValue) | ||
| 23 | { | ||
| 24 | return new NpgsqlParameter(name, type) { Value = DBNull.Value }; | ||
| 25 | } | ||
| 26 | |||
| 27 | return new NpgsqlParameter<T>(name, type) { TypedValue = value.Value }; | ||
| 28 | } | ||
| 29 | |||
| 30 | public static NpgsqlParameter ClassToDbParameter<T>( | ||
| 31 | this T value, | ||
| 32 | string name, | ||
| 33 | NpgsqlDbType type | ||
| 34 | ) | ||
| 35 | where T : class | ||
| 36 | { | ||
| 37 | if (value == null) | ||
| 38 | { | ||
| 39 | return new NpgsqlParameter(name, type) { Value = DBNull.Value }; | ||
| 40 | } | ||
| 41 | |||
| 42 | return new NpgsqlParameter<T>(name, type) { TypedValue = value }; | ||
| 43 | } | ||
| 44 | }{{/code}} | ||
| |
1.1 | 45 | | | |
| 46 | |||
| 47 |