Исходный код вики Сценарии
Версия 1.16 от Alexandr Fokin на 2024/04/13 14:39
Скрыть последних авторов
| author | version | line-number | content |
|---|---|---|---|
| |
1.3 | 1 | |(% style="width:141px" %) |(% style="width:1372px" %) |
| 2 | |(% style="width:141px" %)[[JSON>>doc:Разработка.Схемы данных, контракты, форматы.Text.JSON.WebHome]] тип данных|(% style="width:1372px" %)((( | ||
| |
1.6 | 3 | |(% style="width:117px" %) |(% style="width:1238px" %)Can JSONB GIN indexes be specified in CodeFirst EntityFramework with NPGSQL? |
| |
1.1 | 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]] |
| |
1.8 | 5 | |(% style="width:117px" %)Тип столбца и свойства|(% style="width:1238px" %)((( |
| |
1.4 | 6 | JSON Mapping |
| 7 | [[https:~~/~~/www.npgsql.org/efcore/mapping/json.html?tabs=data-annotations%2Cpoco>>https://www.npgsql.org/efcore/mapping/json.html?tabs=data-annotations%2Cpoco]] | ||
| 8 | |||
| 9 | [[System. Text. Json>>doc:Разработка.NET.Библиотеки.Документы.Форматы данных и схемы.NET Json.System\. Text\. Json.WebHome]] | ||
| |
1.3 | 10 | Позволяет использовать JsonDocument и JsonElement. |
| |
1.4 | 11 | ))) |
| |
1.6 | 12 | |(% style="width:117px" %)Отчистка JsonDocument|(% style="width:1238px" %)1) Вызываем Dispose в setter для предыдущего значения. |
| |
1.5 | 13 | 2) Делаем сущность Disposable и строим отчистку через Dispose DbContext. |
| |
1.7 | 14 | |(% style="width:117px" %)Проблема форматирования|(% style="width:1238px" %)((( |
| |
1.16 | 15 | |(% style="width:151px" %) |(% style="width:1002px" %)((( |
| |
1.7 | 16 | Проблема указания параметров форматирования, с которыми будет выполняться чтение и запись json столбца. |
| 17 | |||
| 18 | Serialization options for System.Text.Json support | ||
| 19 | [[https:~~/~~/github.com/npgsql/efcore.pg/issues/1107>>https://github.com/npgsql/efcore.pg/issues/1107]] | ||
| |
1.10 | 20 | )))| |
| |
1.16 | 21 | |(% style="width:151px" %) |(% style="width:1002px" %)XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions |
| |
1.10 | 22 | [[https:~~/~~/www.nuget.org/packages/XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions/>>https://www.nuget.org/packages/XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions/]]| |
| |
1.16 | 23 | |(% style="width:151px" %)Простое решение|(% style="width:1002px" %)Реализовать кастомный {{code language="c#"}}ValueConverter<JsonElement, string>{{/code}}, определив в нем {{code language="c#"}}JsonSerializerOptions{{/code}}| |
| 24 | |(% style="width:151px" %)Решение через маппинг ADO|(% style="width:1002px" %)((( | ||
| |
1.14 | 25 | NpgsqlConnection.GlobalTypeMapper.Mappings |
| 26 | [[https:~~/~~/github.com/npgsql/efcore.pg/issues/1107#issuecomment-552182608>>https://github.com/npgsql/efcore.pg/issues/1107#issuecomment-552182608]] | ||
| |
1.15 | 27 | |
| 28 | 6.0.0 | ||
| |
1.16 | 29 | [[https:~~/~~/github.com/npgsql/efcore.pg/issues/1107#issuecomment-945126627>>https://github.com/npgsql/efcore.pg/issues/1107#issuecomment-945126627]] |
| |
1.14 | 30 | ))) |
| |
1.3 | 31 | ))) |
| |
1.7 | 32 | ))) |
| |
1.3 | 33 | |(% style="width:141px" %)Parameters|(% style="width:1372px" %){{code language="c#"}}public static class QueryParameterExtensions |
| |
1.2 | 34 | { |
| 35 | public static NpgsqlParameter StructToDbParameter<T>( | ||
| 36 | this T value, | ||
| 37 | string name, | ||
| 38 | NpgsqlDbType type | ||
| 39 | ) | ||
| 40 | where T : struct | ||
| 41 | { | ||
| 42 | return new NpgsqlParameter<T>(name, type) { TypedValue = value }; | ||
| 43 | } | ||
| 44 | |||
| 45 | public static NpgsqlParameter StructToDbParameter<T>( | ||
| 46 | this T? value, | ||
| 47 | string name, | ||
| 48 | NpgsqlDbType type | ||
| 49 | ) | ||
| 50 | where T : struct | ||
| 51 | { | ||
| 52 | if (!value.HasValue) | ||
| 53 | { | ||
| 54 | return new NpgsqlParameter(name, type) { Value = DBNull.Value }; | ||
| 55 | } | ||
| 56 | |||
| 57 | return new NpgsqlParameter<T>(name, type) { TypedValue = value.Value }; | ||
| 58 | } | ||
| 59 | |||
| 60 | public static NpgsqlParameter ClassToDbParameter<T>( | ||
| 61 | this T value, | ||
| 62 | string name, | ||
| 63 | NpgsqlDbType type | ||
| 64 | ) | ||
| 65 | where T : class | ||
| 66 | { | ||
| 67 | if (value == null) | ||
| 68 | { | ||
| 69 | return new NpgsqlParameter(name, type) { Value = DBNull.Value }; | ||
| 70 | } | ||
| 71 | |||
| 72 | return new NpgsqlParameter<T>(name, type) { TypedValue = value }; | ||
| 73 | } | ||
| 74 | }{{/code}} | ||
| |
1.3 | 75 | |(% style="width:141px" %) |(% style="width:1372px" %) |
| |
1.1 | 76 | |
| 77 |