Skip to content

Commit

Permalink
Merge pull request #4 from PandaTechAM/development
Browse files Browse the repository at this point in the history
upgraded to .net 9
  • Loading branch information
HaikAsatryan authored Nov 21, 2024
2 parents 58e33c1 + 36657a0 commit 89e4d00
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 257 deletions.
191 changes: 191 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
###############################
# PandaTech Editor Config #
###############################


################################
# ReSharper Generated Settings #
################################

[*]
charset = utf-8-bom
end_of_line = crlf
trim_trailing_whitespace = false
insert_final_newline = false
indent_style = space
indent_size = 4

# Microsoft .NET properties
csharp_preferred_modifier_order = public, private, protected, internal, file, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True
dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field
dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef
dotnet_naming_rule.unity_serialized_field_rule.severity = warning
dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style
dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion

# ReSharper properties
resharper_align_linq_query = true
resharper_align_multiline_calls_chain = true
resharper_apply_auto_detected_rules = false
resharper_braces_for_for = required
resharper_braces_for_foreach = required
resharper_braces_for_ifelse = required
resharper_braces_for_while = required
resharper_cpp_insert_final_newline = true
resharper_csharp_indent_size = 3
resharper_csharp_max_enum_members_on_line = 0
resharper_csharp_tab_width = 3
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_parameters_style = chop_if_long
resharper_formatter_off_tag = @formatter:off
resharper_formatter_on_tag = @formatter:on
resharper_formatter_tags_enabled = true
resharper_keep_existing_declaration_parens_arrangement = false
resharper_keep_existing_expr_member_arrangement = false
resharper_keep_existing_initializer_arrangement = false
resharper_keep_existing_switch_expression_arrangement = false
resharper_max_array_initializer_elements_on_line = 0
resharper_max_initializer_elements_on_line = 0
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_accessor_attribute_on_same_line = false
resharper_place_field_attribute_on_same_line = false
resharper_place_simple_anonymousmethod_on_single_line = false
resharper_place_simple_embedded_statement_on_same_line = false
resharper_place_simple_initializer_on_single_line = false
resharper_place_simple_property_pattern_on_single_line = false
resharper_use_indent_from_vs = false
resharper_wrap_after_property_in_chained_method_calls = true
resharper_wrap_array_initializer_style = chop_if_long
resharper_wrap_chained_method_calls = chop_always
resharper_wrap_linq_expressions = chop_always
resharper_wrap_list_pattern = chop_if_long
resharper_wrap_object_and_collection_initializer_style = chop_always
resharper_wrap_property_pattern = chop_always

# ReSharper inspection severities
resharper_arrange_redundant_parentheses_highlighting = hint
resharper_arrange_this_qualifier_highlighting = hint
resharper_arrange_type_member_modifiers_highlighting = hint
resharper_arrange_type_modifiers_highlighting = hint
resharper_built_in_type_reference_style_for_member_access_highlighting = hint
resharper_built_in_type_reference_style_highlighting = hint
resharper_enforce_foreach_statement_braces_highlighting = warning
resharper_enforce_for_statement_braces_highlighting = warning
resharper_enforce_if_statement_braces_highlighting = warning
resharper_enforce_lock_statement_braces_highlighting = warning
resharper_enforce_using_statement_braces_highlighting = warning
resharper_enforce_while_statement_braces_highlighting = warning
resharper_mvc_action_not_resolved_highlighting = warning
resharper_mvc_area_not_resolved_highlighting = warning
resharper_mvc_controller_not_resolved_highlighting = warning
resharper_mvc_masterpage_not_resolved_highlighting = warning
resharper_mvc_partial_view_not_resolved_highlighting = warning
resharper_mvc_template_not_resolved_highlighting = warning
resharper_mvc_view_component_not_resolved_highlighting = warning
resharper_mvc_view_component_view_not_resolved_highlighting = warning
resharper_mvc_view_not_resolved_highlighting = warning
resharper_razor_assembly_not_resolved_highlighting = warning
resharper_redundant_base_qualifier_highlighting = warning
resharper_web_config_module_not_resolved_highlighting = warning
resharper_web_config_type_not_resolved_highlighting = warning
resharper_web_config_wrong_module_highlighting = warning

[{*.har,*.jsb2,*.jsb3,*.json,*.jsonc,*.postman_collection,*.postman_collection.json,*.postman_environment,*.postman_environment.json,.babelrc,.eslintrc,.prettierrc,.stylelintrc,.ws-context,bowerrc,jest.config}]
indent_style = space
indent_size = 2

[{*.yaml,*.yml}]
indent_style = space
indent_size = 2

[*.cs]
indent_style = space
indent_size = 3
tab_width = 3

[*.{appxmanifest,asax,ascx,aspx,axaml,build,c,c++,c++m,cc,ccm,cginc,compute,cp,cpp,cppm,cshtml,cu,cuh,cxx,cxxm,dtd,fs,fsi,fsscript,fsx,fx,fxh,h,hh,hlsl,hlsli,hlslinc,hpp,hxx,inc,inl,ino,ipp,ixx,master,ml,mli,mpp,mq4,mq5,mqh,mxx,nuspec,paml,razor,resw,resx,shader,skin,tpp,usf,ush,uxml,vb,xaml,xamlx,xoml,xsd}]
indent_style = space
indent_size = 4
tab_width = 4

#########################
# Custom added settings #
#########################
[*.cs]
dotnet_diagnostic.cs8600.severity = error #Converting null literal or possible null value to non-nullable type.
dotnet_diagnostic.cs8601.severity = error #Possible null reference assignment.
dotnet_diagnostic.cs8602.severity = error #possible dereference of a null reference
dotnet_diagnostic.cs8603.severity = error #possible null reference return
dotnet_diagnostic.cs8604.severity = error #possible null reference argument for parameter
dotnet_diagnostic.cs8605.severity = error #Unboxing a possibly null value
dotnet_diagnostic.cs8618.severity = error # Non-nullable field is uninitialized. Consider declaring as nullable.
dotnet_diagnostic.cs8625.severity = error # Cannot convert null literal to non-nullable reference type.
dotnet_diagnostic.cs8762.severity = error # Nullability of reference types in type doesn't match overridden member.
dotnet_diagnostic.cs1717.severity = error #variable is assigned to itself
dotnet_diagnostic.cs1718.severity = error #comparison made to same variable
dotnet_diagnostic.cs0659.severity = error #overriding object.Equals but not overriding object.GetHashCode
dotnet_diagnostic.cs0251.severity = error #Indexing an array with a negative index (array indices always start at zero)
dotnet_diagnostic.s3363.severity = none #Never set DateTime as PrimaryKey. Ignored as we never do it but have warnings for cache entities.
dotnet_diagnostic.ca2016.severity = error #Forwarding cancellation tokens
csharp_style_namespace_declarations = file_scoped:error
resharper_entity_framework_model_validation_unlimited_string_length_highlighting = none


#########################
# VS added settings #
#########################

[*.cs]
csharp_style_namespace_declarations = file_scoped:error
csharp_indent_labels = one_less_than_current
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent

[{*.yaml,*.yml}]
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 3
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent

[*.csv]
indent_style = tab
tab_width = 4
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

Expand Down
1 change: 1 addition & 0 deletions EFCore.PostgresExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
Readme.md = Readme.md
global.json = global.json
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
Expand Down
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ public partial class PgFunction : Migration
}
}
```

#### Additional notes
- The random incrementing sequence feature ensures the generated IDs are unique, non-sequential, and non-predictable, enhancing security.
- The feature supports only `long` data type (`bigint` in PostgreSQL).

- The random incrementing sequence feature ensures the generated IDs are unique, non-sequential, and non-predictable,
enhancing security.
- The feature supports only `long` data type (`bigint` in PostgreSQL).

### Npgsql COPY Integration (Obsolete: Use EFCore.BulkExtensions.PostgreSql instead)

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.200",
"rollForward": "latestMajor"
"version": "9.0.100",
"rollForward": "latestMinor"
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>3.0.0</Version>
<Version>4.0.0</Version>
<PackageId>Pandatech.EFCore.PostgresExtensions</PackageId>
<Title>Pandatech.EFCore.PostgresExtensions</Title>
<PackageTags>Pandatech, library, EntityFrameworkCore, PostgreSQL, For Update, Lock, LockingSyntax, Bulk insert, BinaryCopy</PackageTags>
<Description>The Pandatech.EFCore.PostgresExtensions library enriches Entity Framework Core applications with advanced PostgreSQL functionalities, starting with the ForUpdate locking syntax and BulkInsert function. Designed for seamless integration, this NuGet package aims to enhance the efficiency and capabilities of EF Core models when working with PostgreSQL, with the potential for further PostgreSQL-specific extensions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-efcore-postgres-extensions</RepositoryUrl>
<PackageReleaseNotes>Random Incrementing Sequence Generation Feature</PackageReleaseNotes>
<PackageReleaseNotes>.net 9 upgrade</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1"/>
</ItemGroup>

</Project>
56 changes: 29 additions & 27 deletions src/EFCore.PostgresExtensions/Enums/LockBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
namespace EFCore.PostgresExtensions.Enums
{
public enum LockBehavior
{
/// <summary>
/// Using this behavior forces transaction to wait until row is unlocked.
/// </summary>
Default = 0,
namespace EFCore.PostgresExtensions.Enums;

/// <summary>
/// Using this behavior will skip rows that are locked by another transaction.
/// </summary>
SkipLocked = 1,
public enum LockBehavior
{
/// <summary>
/// Using this behavior forces transaction to wait until row is unlocked.
/// </summary>
Default = 0,

/// <summary>
/// Using this behavior will throw an exception if requested rows are locked by another transaction.
/// </summary>
NoWait = 2,
}
/// <summary>
/// Using this behavior will skip rows that are locked by another transaction.
/// </summary>
SkipLocked = 1,

public static class LockBehaviorExtensions
{
public static string GetSqlKeyword(this LockBehavior lockBehavior) => lockBehavior switch
{
LockBehavior.Default => string.Empty,
LockBehavior.SkipLocked => "skip locked",
LockBehavior.NoWait => "nowait",
_ => string.Empty,
};
}
/// <summary>
/// Using this behavior will throw an exception if requested rows are locked by another transaction.
/// </summary>
NoWait = 2
}

public static class LockBehaviorExtensions
{
public static string GetSqlKeyword(this LockBehavior lockBehavior)
{
return lockBehavior switch
{
LockBehavior.Default => string.Empty,
LockBehavior.SkipLocked => "skip locked",
LockBehavior.NoWait => "nowait",
_ => string.Empty
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ private static void ConvertEnumValue<T>(int columnCount,
if (!propertyTypes[i].IsGenericType || propertyTypes[i]
.GetGenericTypeDefinition() != typeof(List<>) ||
!propertyTypes[i]
.GetGenericArguments()[0].IsEnum) continue;
.GetGenericArguments()[0].IsEnum)
{
continue;
}

var enumMapping = properties[i]
.FindTypeMapping();

// Only proceed if the mapping is for an array type, as expected for lists
if (enumMapping is not NpgsqlArrayTypeMapping) continue;
if (enumMapping is not NpgsqlArrayTypeMapping)
{
continue;
}

var list = (IList)values[i]!;
var underlyingType = Enum.GetUnderlyingType(propertyTypes[i]
Expand Down Expand Up @@ -153,9 +159,14 @@ private static DbContext PrepareBulkInsertOperation<T>(DbSet<T> dbSet,


if (entities == null || entities.Count == 0)
{
throw new ArgumentException("The model list cannot be null or empty.");
}

if (context == null) throw new ArgumentNullException(nameof(context), "The DbContext instance cannot be null.");
if (context == null)
{
throw new ArgumentNullException(nameof(context), "The DbContext instance cannot be null.");
}


var entityType = context.Model.FindEntityType(typeof(T))! ??
Expand All @@ -168,14 +179,18 @@ private static DbContext PrepareBulkInsertOperation<T>(DbSet<T> dbSet,
.ToList();

if (pkGeneratedByDb)
{
properties = properties.Where(x => !x.IsKey())
.ToList();
}

var columnNames = properties.Select(x => $"\"{x.GetColumnName()}\"")
.ToList();

if (columnNames.Count == 0)
{
throw new InvalidOperationException("Column names are null or empty.");
}


columnCount = columnNames.Count;
Expand Down
Loading

0 comments on commit 89e4d00

Please sign in to comment.