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

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

<
От версии < 1.17
отредактировано Alexandr Fokin
на 2024/12/07 13:48
К версии < 1.14 >
отредактировано Alexandr Fokin
на 2024/04/13 14:38
Изменить комментарий: К данной версии нет комментариев

Комментарий

Подробности

Свойства страницы
Содержимое
... ... @@ -1,23 +1,79 @@
1 -----
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?
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 +|(% 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]]
2 2  
3 -==== Внутренние ссылки: ====
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 +|(((
16 +Проблема указания параметров форматирования, с которыми будет выполняться чтение и запись json столбца.
4 4  
5 -====== Дочерние страницы: ======
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]]
20 +)))|
21 +|XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions
22 +[[https:~~/~~/www.nuget.org/packages/XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions/>>https://www.nuget.org/packages/XO.EntityFrameworkCore.NpgsqlJsonSerializerOptions/]]|
23 +|Простое решение - реализовать кастомный {{code language="c#"}}ValueConverter<JsonElement, string>{{/code}}, определив в нем {{code language="c#"}}JsonSerializerOptions{{/code}}|
24 +|(((
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]]
27 +)))
6 6  
7 -{{children/}}
29 +{{{
30 +6.0.0
8 8  
9 -====== Обратные ссылки: ======
32 +}}}
33 +)))
34 +)))
35 +|(% style="width:141px" %)Parameters|(% style="width:1372px" %){{code language="c#"}}public static class QueryParameterExtensions
36 +{
37 + public static NpgsqlParameter StructToDbParameter<T>(
38 + this T value,
39 + string name,
40 + NpgsqlDbType type
41 + )
42 + where T : struct
43 + {
44 + return new NpgsqlParameter<T>(name, type) { TypedValue = value };
45 + }
10 10  
11 -{{velocity}}
12 -#set ($links = $doc.getBacklinks())
13 -#if ($links.size() > 0)
14 - #foreach ($docname in $links)
15 - #set ($rdoc = $xwiki.getDocument($docname).getTranslatedDocument())
16 - * [[$escapetool.xml($rdoc.fullName)]]
17 - #end
18 -#else
19 - No back links for this page!
20 -#end
21 -{{/velocity}}
47 + public static NpgsqlParameter StructToDbParameter<T>(
48 + this T? value,
49 + string name,
50 + NpgsqlDbType type
51 + )
52 + where T : struct
53 + {
54 + if (!value.HasValue)
55 + {
56 + return new NpgsqlParameter(name, type) { Value = DBNull.Value };
57 + }
22 22  
23 -----
59 + return new NpgsqlParameter<T>(name, type) { TypedValue = value.Value };
60 + }
61 +
62 + public static NpgsqlParameter ClassToDbParameter<T>(
63 + this T value,
64 + string name,
65 + NpgsqlDbType type
66 + )
67 + where T : class
68 + {
69 + if (value == null)
70 + {
71 + return new NpgsqlParameter(name, type) { Value = DBNull.Value };
72 + }
73 +
74 + return new NpgsqlParameter<T>(name, type) { TypedValue = value };
75 + }
76 +}{{/code}}
77 +|(% style="width:141px" %) |(% style="width:1372px" %)
78 +
79 +