Изменения документа Сценарии

Редактировал(а) Alexandr Fokin 2024/12/07 13:48

От версии 1.1 >
отредактировано Alexandr Fokin
на 2023/02/11 21:51
К версии < 1.9 >
отредактировано Alexandr Fokin
на 2024/03/02 20:27
>
Изменить комментарий: К данной версии нет комментариев

Комментарий

Подробности

Свойства страницы
Содержимое
... ... @@ -1,6 +1,68 @@
1 -| |Can JSONB GIN indexes be specified in CodeFirst EntityFramework with NPGSQL?
1 +|(% style="width:141px" %) |(% style="width:1372px" %)
2 +|(% style="width:141px" %)[[JSON>>doc:Разработка.Схемы данных, контракты, форматы.Text.JSON.WebHome]] тип данных|(% style="width:1372px" %)(((
3 +|(% style="width:117px" %) |(% style="width:1238px" %)Can JSONB GIN indexes be specified in CodeFirst EntityFramework with NPGSQL?
2 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]]
3 -| |
4 -| |
5 +|(% style="width:117px" %)Тип столбца и свойства|(% style="width:1238px" %)(((
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]]
5 5  
9 +[[System. Text. Json>>doc:Разработка.NET.Библиотеки.Документы.Форматы данных и схемы.NET Json.System\. Text\. Json.WebHome]]
10 +Позволяет использовать JsonDocument и JsonElement.
11 +)))
12 +|(% style="width:117px" %)Отчистка JsonDocument|(% style="width:1238px" %)1) Вызываем Dispose в setter для предыдущего значения.
13 +2) Делаем сущность Disposable и строим отчистку через Dispose DbContext.
14 +|(% style="width:117px" %)Проблема форматирования|(% style="width:1238px" %)(((
15 +Проблема указания параметров форматирования, с которыми будет выполняться чтение и запись json столбца.
16 +
17 +Serialization options for System.Text.Json support
18 +[[https:~~/~~/github.com/npgsql/efcore.pg/issues/1107>>https://github.com/npgsql/efcore.pg/issues/1107]]
19 +
20 +XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions
21 +[[https:~~/~~/www.nuget.org/packages/XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions/>>https://www.nuget.org/packages/XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions/]]
22 +)))
23 +)))
24 +|(% style="width:141px" %)Parameters|(% style="width:1372px" %){{code language="c#"}}public static class QueryParameterExtensions
25 +{
26 + public static NpgsqlParameter StructToDbParameter<T>(
27 + this T value,
28 + string name,
29 + NpgsqlDbType type
30 + )
31 + where T : struct
32 + {
33 + return new NpgsqlParameter<T>(name, type) { TypedValue = value };
34 + }
35 +
36 + public static NpgsqlParameter StructToDbParameter<T>(
37 + this T? value,
38 + string name,
39 + NpgsqlDbType type
40 + )
41 + where T : struct
42 + {
43 + if (!value.HasValue)
44 + {
45 + return new NpgsqlParameter(name, type) { Value = DBNull.Value };
46 + }
47 +
48 + return new NpgsqlParameter<T>(name, type) { TypedValue = value.Value };
49 + }
50 +
51 + public static NpgsqlParameter ClassToDbParameter<T>(
52 + this T value,
53 + string name,
54 + NpgsqlDbType type
55 + )
56 + where T : class
57 + {
58 + if (value == null)
59 + {
60 + return new NpgsqlParameter(name, type) { Value = DBNull.Value };
61 + }
62 +
63 + return new NpgsqlParameter<T>(name, type) { TypedValue = value };
64 + }
65 +}{{/code}}
66 +|(% style="width:141px" %) |(% style="width:1372px" %)
67 +
6 6