Исходный код вики Сценарии
Версия 1.3 от Alexandr Fokin на 2024/02/24 15:12
Последние авторы
| author | version | line-number | content |
|---|---|---|---|
| 1 | |(% style="width:141px" %) |(% style="width:1372px" %) | ||
| 2 | |(% style="width:141px" %)[[JSON>>doc:Разработка.Схемы данных, контракты, форматы.Text.JSON.WebHome]] тип данных|(% style="width:1372px" %)((( | ||
| 3 | | |Can JSONB GIN indexes be specified in CodeFirst EntityFramework with NPGSQL? | ||
| 4 | [[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]] | ||
| 5 | |Тип сущности|[[System. Text. Json>>doc:Разработка.NET.Библиотеки.Документы.Форматы данных и схемы.NET Json.System\. Text\. Json.WebHome]] | ||
| 6 | Позволяет использовать JsonDocument и JsonElement. | ||
| 7 | | | | ||
| 8 | ))) | ||
| 9 | |(% style="width:141px" %)Parameters|(% style="width:1372px" %){{code language="c#"}}public static class QueryParameterExtensions | ||
| 10 | { | ||
| 11 | public static NpgsqlParameter StructToDbParameter<T>( | ||
| 12 | this T value, | ||
| 13 | string name, | ||
| 14 | NpgsqlDbType type | ||
| 15 | ) | ||
| 16 | where T : struct | ||
| 17 | { | ||
| 18 | return new NpgsqlParameter<T>(name, type) { TypedValue = value }; | ||
| 19 | } | ||
| 20 | |||
| 21 | public static NpgsqlParameter StructToDbParameter<T>( | ||
| 22 | this T? value, | ||
| 23 | string name, | ||
| 24 | NpgsqlDbType type | ||
| 25 | ) | ||
| 26 | where T : struct | ||
| 27 | { | ||
| 28 | if (!value.HasValue) | ||
| 29 | { | ||
| 30 | return new NpgsqlParameter(name, type) { Value = DBNull.Value }; | ||
| 31 | } | ||
| 32 | |||
| 33 | return new NpgsqlParameter<T>(name, type) { TypedValue = value.Value }; | ||
| 34 | } | ||
| 35 | |||
| 36 | public static NpgsqlParameter ClassToDbParameter<T>( | ||
| 37 | this T value, | ||
| 38 | string name, | ||
| 39 | NpgsqlDbType type | ||
| 40 | ) | ||
| 41 | where T : class | ||
| 42 | { | ||
| 43 | if (value == null) | ||
| 44 | { | ||
| 45 | return new NpgsqlParameter(name, type) { Value = DBNull.Value }; | ||
| 46 | } | ||
| 47 | |||
| 48 | return new NpgsqlParameter<T>(name, type) { TypedValue = value }; | ||
| 49 | } | ||
| 50 | }{{/code}} | ||
| 51 | |(% style="width:141px" %) |(% style="width:1372px" %) | ||
| 52 | |||
| 53 |