diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..99aa104 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,245 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# C# files +[*.cs] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = false + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = true +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false +dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_method = false +dotnet_style_qualification_for_property = false + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true +dotnet_style_predefined_type_for_member_access = true + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity +dotnet_style_parentheses_in_other_operators = never_if_unnecessary +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# Expression-level preferences +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = true +dotnet_style_explicit_tuple_names = true +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true +dotnet_style_prefer_collection_expression = when_types_loosely_match +dotnet_style_prefer_compound_assignment = true +dotnet_style_prefer_conditional_expression_over_assignment = true +dotnet_style_prefer_conditional_expression_over_return = true +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed +dotnet_style_prefer_inferred_anonymous_type_member_names = true +dotnet_style_prefer_inferred_tuple_names = true +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true +dotnet_style_prefer_simplified_interpolation = true + +# Field preferences +dotnet_style_readonly_field = true + +# Parameter preferences +dotnet_code_quality_unused_parameters = all + +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none + +# New line preferences +dotnet_style_allow_multiple_blank_lines_experimental = false +dotnet_style_allow_statement_immediately_after_block_experimental = true + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false +csharp_style_var_for_built_in_types = false +csharp_style_var_when_type_is_apparent = false + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true +csharp_style_expression_bodied_constructors = false +csharp_style_expression_bodied_indexers = true +csharp_style_expression_bodied_lambdas = true +csharp_style_expression_bodied_local_functions = false +csharp_style_expression_bodied_methods = false +csharp_style_expression_bodied_operators = false +csharp_style_expression_bodied_properties = true + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_extended_property_pattern = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true +csharp_style_prefer_switch_expression = true + +# Null-checking preferences +csharp_style_conditional_delegate_call = true + +# Modifier preferences +csharp_prefer_static_anonymous_function = true +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_style_prefer_readonly_struct = true +csharp_style_prefer_readonly_struct_member = true + +# Code-block preferences +csharp_prefer_braces = true +csharp_prefer_simple_using_statement = true +csharp_style_namespace_declarations = block_scoped +csharp_style_prefer_method_group_conversion = true +csharp_style_prefer_primary_constructors = true +csharp_style_prefer_top_level_statements = true + +# Expression-level preferences +csharp_prefer_simple_default_expression = true +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = true +csharp_style_inlined_variable_declaration = true +csharp_style_prefer_index_operator = true +csharp_style_prefer_local_over_anonymous_function = true +csharp_style_prefer_null_check_over_type_check = true +csharp_style_prefer_range_operator = true +csharp_style_prefer_tuple_swap = true +csharp_style_prefer_utf8_string_literals = true +csharp_style_throw_expression = true +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace + +# New line preferences +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false +csharp_style_allow_embedded_statements_on_same_line_experimental = true + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.private_or_internal_field_should_be__fieldname.severity = suggestion +dotnet_naming_rule.private_or_internal_field_should_be__fieldname.symbols = private_or_internal_field +dotnet_naming_rule.private_or_internal_field_should_be__fieldname.style = _fieldname + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected +dotnet_naming_symbols.private_or_internal_field.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style._fieldname.required_prefix = _ +dotnet_naming_style._fieldname.required_suffix = +dotnet_naming_style._fieldname.word_separator = +dotnet_naming_style._fieldname.capitalization = camel_case diff --git a/N.EntityFrameworkCore.Extensions.Test/Common/Config.cs b/N.EntityFrameworkCore.Extensions.Test/Common/Config.cs index 8fda5ff..9cd853c 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Common/Config.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Common/Config.cs @@ -1,7 +1,7 @@ -using Microsoft.Extensions.Configuration; -using System; +using System; using System.Collections.Generic; using System.Text; +using Microsoft.Extensions.Configuration; namespace N.EntityFrameworkCore.Extensions.Test.Common { @@ -15,4 +15,4 @@ public static string GetConnectionString(string name) return builder.Build().GetConnectionString(name); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/Enums/ProductStatus.cs b/N.EntityFrameworkCore.Extensions.Test/Data/Enums/ProductStatus.cs index acb3da3..0e19e97 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/Enums/ProductStatus.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/Enums/ProductStatus.cs @@ -11,4 +11,4 @@ public enum ProductStatus InStock, OutOfStock, } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/Order.cs b/N.EntityFrameworkCore.Extensions.Test/Data/Order.cs index 99b92c4..f82ab52 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/Order.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/Order.cs @@ -29,6 +29,6 @@ public enum OrderStatus { Unknown, Completed, - Error + Error } } \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/Position.cs b/N.EntityFrameworkCore.Extensions.Test/Data/Position.cs index 734c7e0..0fe3b65 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/Position.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/Position.cs @@ -12,4 +12,4 @@ public class Position public int Aisle; public int Bay; } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/Product.cs b/N.EntityFrameworkCore.Extensions.Test/Data/Product.cs index 89fd091..da60e06 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/Product.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/Product.cs @@ -1,9 +1,9 @@ -using N.EntityFrameworkCore.Extensions.Test.Data.Enums; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text; +using N.EntityFrameworkCore.Extensions.Test.Data.Enums; namespace N.EntityFrameworkCore.Extensions.Test.Data { @@ -32,4 +32,4 @@ public Product() } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/ProductCategory.cs b/N.EntityFrameworkCore.Extensions.Test/Data/ProductCategory.cs index edb09b3..7ff35e9 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/ProductCategory.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/ProductCategory.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data.Enums; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data.Enums; namespace N.EntityFrameworkCore.Extensions.Test.Data { @@ -14,4 +14,4 @@ public class ProductCategory public string Name { get; set; } public bool Active { get; internal set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithComplexKey.cs b/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithComplexKey.cs index e149e0e..3e495f5 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithComplexKey.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithComplexKey.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -26,4 +26,4 @@ public ProductWithComplexKey() //Key3 = Guid.NewGuid(); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithCustomSchema.cs b/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithCustomSchema.cs index 1aa95f0..71d314e 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithCustomSchema.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/ProductWithCustomSchema.cs @@ -1,9 +1,9 @@ -using N.EntityFrameworkCore.Extensions.Test.Data.Enums; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text; +using N.EntityFrameworkCore.Extensions.Test.Data.Enums; namespace N.EntityFrameworkCore.Extensions.Test.Data { @@ -16,4 +16,4 @@ public class ProductWithCustomSchema public string Name { get; set; } public decimal Price { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/TestDbContext.cs b/N.EntityFrameworkCore.Extensions.Test/Data/TestDbContext.cs index e5e64bd..86d9433 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/TestDbContext.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/TestDbContext.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using N.EntityFrameworkCore.Extensions.Test.Common; -using System; +using System; using System.ComponentModel.DataAnnotations.Schema; using System.Drawing; using System.Reflection.Metadata; using System.Runtime.ConstrainedExecution; +using Microsoft.EntityFrameworkCore; +using N.EntityFrameworkCore.Extensions.Test.Common; namespace N.EntityFrameworkCore.Extensions.Test.Data { @@ -14,7 +14,7 @@ public class TestDbContext : DbContext public virtual DbSet ProductCategories { get; set; } public virtual DbSet ProductsWithCustomSchema { get; set; } public virtual DbSet ProductsWithComplexKey { get; set; } - public virtual DbSet Orders { get; set; } + public virtual DbSet Orders { get; set; } public virtual DbSet TpcPeople { get; set; } public virtual DbSet TphPeople { get; set; } public virtual DbSet TphCustomers { get; set; } @@ -52,4 +52,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) }); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/TpcCustomer.cs b/N.EntityFrameworkCore.Extensions.Test/Data/TpcCustomer.cs index e2d6593..983cd25 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/TpcCustomer.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/TpcCustomer.cs @@ -8,4 +8,4 @@ public class TpcCustomer : TpcPerson public string Phone { get; set; } public DateTime AddedDate { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/TpcPerson.cs b/N.EntityFrameworkCore.Extensions.Test/Data/TpcPerson.cs index 9c8d9da..1659a4f 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/TpcPerson.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/TpcPerson.cs @@ -9,4 +9,4 @@ public abstract class TpcPerson public string FirstName { get; set; } public string LastName { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/TphCustomer.cs b/N.EntityFrameworkCore.Extensions.Test/Data/TphCustomer.cs index e639c04..28cdf15 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/TphCustomer.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/TphCustomer.cs @@ -8,4 +8,4 @@ public class TphCustomer : TphPerson public string Phone { get; set; } public DateTime AddedDate { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/TptCustomer.cs b/N.EntityFrameworkCore.Extensions.Test/Data/TptCustomer.cs index e9fe899..2256f2b 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/TptCustomer.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/TptCustomer.cs @@ -8,4 +8,4 @@ public class TptCustomer : TptPerson public string Phone { get; set; } public DateTime AddedDate { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/Data/TptPerson.cs b/N.EntityFrameworkCore.Extensions.Test/Data/TptPerson.cs index 9dedb6f..20ef993 100644 --- a/N.EntityFrameworkCore.Extensions.Test/Data/TptPerson.cs +++ b/N.EntityFrameworkCore.Extensions.Test/Data/TptPerson.cs @@ -9,4 +9,4 @@ public class TptPerson public string FirstName { get; set; } public string LastName { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/DatabaseExtensionsBase.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/DatabaseExtensionsBase.cs index f980a47..e974880 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/DatabaseExtensionsBase.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/DatabaseExtensionsBase.cs @@ -1,10 +1,10 @@ -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -13,7 +13,7 @@ public class DatabaseExtensionsBase protected TestDbContext SetupDbContext(bool populateData) { TestDbContext dbContext = new TestDbContext(); - dbContext.Database.EnsureCreated(); + dbContext.Database.EnsureCreated(); dbContext.Orders.Truncate(); if (populateData) { @@ -59,4 +59,4 @@ protected TestDbContext SetupDbContext(bool populateData) return dbContext; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFile.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFile.cs index c575482..1df2c8a 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFile.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFile.cs @@ -1,10 +1,10 @@ -using Microsoft.Data.SqlClient; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -36,4 +36,4 @@ public void With_Options_ColumnDelimiter_TextQualifer() Assert.IsTrue(queryToCsvFileResult.TotalRowCount == count + 1, "The total number of rows written to the file should match the count from the database plus the header row"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFileAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFileAsync.cs index b1da288..3d57c38 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFileAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQueryToCsvFileAsync.cs @@ -1,10 +1,10 @@ -using Microsoft.Data.SqlClient; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -16,7 +16,7 @@ public async Task With_Default_Options() { var dbContext = SetupDbContext(true); int count = dbContext.Orders.Where(o => o.Price > 5M).Count(); - var queryToCsvFileResult = await dbContext.Database.SqlQueryToCsvFileAsync("SqlQueryToCsvFile-Test.csv", "SELECT * FROM Orders WHERE Price > @Price", new object[] { new SqlParameter("@Price", 5M) } ); + var queryToCsvFileResult = await dbContext.Database.SqlQueryToCsvFileAsync("SqlQueryToCsvFile-Test.csv", "SELECT * FROM Orders WHERE Price > @Price", new object[] { new SqlParameter("@Price", 5M) }); Assert.IsTrue(count > 0, "There should be existing data in the source table"); Assert.IsTrue(queryToCsvFileResult.DataRowCount == count, "The number of data rows written to the file should match the count from the database"); @@ -36,4 +36,4 @@ public async Task With_Options_ColumnDelimiter_TextQualifer() Assert.IsTrue(queryToCsvFileResult.TotalRowCount == count + 1, "The total number of rows written to the file should match the count from the database plus the header row"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_Count.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_Count.cs index 5d2abcb..ec87927 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_Count.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_Count.cs @@ -1,6 +1,6 @@ -using Microsoft.Data.SqlClient; +using System.Linq; +using Microsoft.Data.SqlClient; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -30,4 +30,4 @@ public void With_OrderBy() Assert.IsTrue(efCount == sqlCount, "Count from EF should match the count from the SqlQuery"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_CountAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_CountAsync.cs index 355c395..4d837ee 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_CountAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/SqlQuery_CountAsync.cs @@ -1,7 +1,7 @@ -using Microsoft.Data.SqlClient; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; +using System.Linq; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -31,4 +31,4 @@ public async Task With_OrderBy() Assert.IsTrue(efCount == sqlCount, "Count from EF should match the count from the SqlQuery"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TableExists.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TableExists.cs index 5bb3dc8..dfe2d9f 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TableExists.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TableExists.cs @@ -1,9 +1,9 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -22,4 +22,4 @@ public void With_Orders_Table() Assert.IsTrue(!orderNewTableExists, "Orders_New table should not exist"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTable.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTable.cs index b019ce9..9028dfa 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTable.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTable.cs @@ -1,9 +1,9 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { @@ -22,4 +22,4 @@ public void With_Orders_Table() Assert.IsTrue(newOrdersCount == 0, "Order table should be empty after truncating"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTableAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTableAsync.cs index 1a00d12..5dcc1ac 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTableAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DatabaseExtensions/TruncateTableAsync.cs @@ -1,14 +1,14 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DatabaseExtensions { [TestClass] - public class TruncateTableAsync :DatabaseExtensionsBase + public class TruncateTableAsync : DatabaseExtensionsBase { [TestMethod] public async Task With_Orders_Table() @@ -22,4 +22,4 @@ public async Task With_Orders_Table() Assert.IsTrue(newOrdersCount == 0, "Order table should be empty after truncating"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDelete.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDelete.cs index 08c6a03..b2eafa5 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDelete.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDelete.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System.Linq; +using System.Linq; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -89,4 +89,4 @@ public void With_Transaction() Assert.IsTrue(rollbackTotal == orders.Count, "The number of rows after the transacation has been rollbacked should match the original count"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDeleteAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDeleteAsync.cs index 54c1b44..bcaa87e 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDeleteAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkDeleteAsync.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System.Linq; +using System.Linq; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -89,4 +89,4 @@ public async Task With_Transaction() Assert.IsTrue(rollbackTotal == orders.Count, "The number of rows after the transacation has been rollbacked should match the original count"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkFetch.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkFetch.cs index 9a86b0d..de7f31b 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkFetch.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkFetch.cs @@ -1,9 +1,9 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -116,4 +116,4 @@ public void With_ValueConverter() Assert.IsTrue(areMatched, "The products from BulkFetch() should match what is retrieved from DbContext"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsert.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsert.cs index d688a02..d0b7a81 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsert.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsert.cs @@ -1,9 +1,9 @@ -using Microsoft.Data.SqlClient; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Data.SqlClient; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -215,7 +215,7 @@ public void With_Options_IgnoreColumns() orders.Add(new Order { Id = i, ExternalId = i.ToString(), Price = 1.57M, Active = true }); } int oldTotal = dbContext.Orders.Where(o => o.Price <= 10 && o.ExternalId == null).Count(); - int rowsInserted = dbContext.BulkInsert(orders, options => { options.UsePermanentTable = true; options.IgnoreColumns = o => new { o.ExternalId };}); + int rowsInserted = dbContext.BulkInsert(orders, options => { options.UsePermanentTable = true; options.IgnoreColumns = o => new { o.ExternalId }; }); int newTotal = dbContext.Orders.Where(o => o.Price <= 10 && o.ExternalId == null).Count(); Assert.IsTrue(rowsInserted == orders.Count, "The number of rows inserted must match the count of order list"); @@ -228,11 +228,14 @@ public void With_Options_InputColumns() var orders = new List(); for (int i = 0; i < 20000; i++) { - orders.Add(new Order { Id = i, ExternalId = i.ToString(), Price = 1.57M, Active = true, Status = OrderStatus.Completed}); + orders.Add(new Order { Id = i, ExternalId = i.ToString(), Price = 1.57M, Active = true, Status = OrderStatus.Completed }); } int oldTotal = dbContext.Orders.Where(o => o.Price == 1.57M && o.ExternalId == null && o.Active == true).Count(); - int rowsInserted = dbContext.BulkInsert(orders, options => { options.UsePermanentTable = true; - options.InputColumns = o => new { o.Price, o.Active, o.AddedDateTime, o.Status }; }); + int rowsInserted = dbContext.BulkInsert(orders, options => + { + options.UsePermanentTable = true; + options.InputColumns = o => new { o.Price, o.Active, o.AddedDateTime, o.Status }; + }); int newTotal = dbContext.Orders.Where(o => o.Price == 1.57M && o.ExternalId == null && o.Active == true).Count(); Assert.IsTrue(rowsInserted == orders.Count, "The number of rows inserted must match the count of order list"); @@ -286,11 +289,11 @@ public void With_Schema() for (int i = 1; i < 10000; i++) { var key = i.ToString(); - products.Add(new ProductWithCustomSchema + products.Add(new ProductWithCustomSchema { Id = key, - Name = $"Product-{key}", - Price = 1.57M + Name = $"Product-{key}", + Price = 1.57M }); } int oldTotal = dbContext.ProductsWithCustomSchema.Where(o => o.Price <= 10).Count(); @@ -379,4 +382,4 @@ public void With_ValueGenerated_Computed() Assert.IsTrue(newTotal - oldTotal == rowsInserted, "The new count minus the old count should match the number of rows inserted."); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsertAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsertAsync.cs index b576ebb..2fd0a34 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsertAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkInsertAsync.cs @@ -1,10 +1,10 @@ -using Microsoft.Data.SqlClient; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -247,11 +247,14 @@ public async Task With_Options_InputColumns() var orders = new List(); for (int i = 0; i < 20000; i++) { - orders.Add(new Order { Id = i, ExternalId = i.ToString(), Price = 1.57M, Active = true, Status = OrderStatus.Completed}); + orders.Add(new Order { Id = i, ExternalId = i.ToString(), Price = 1.57M, Active = true, Status = OrderStatus.Completed }); } int oldTotal = dbContext.Orders.Where(o => o.Price == 1.57M && o.ExternalId == null && o.Active == true).Count(); - int rowsInserted = await dbContext.BulkInsertAsync(orders, options => { options.UsePermanentTable = true; - options.InputColumns = o => new { o.Price, o.Active, o.AddedDateTime, o.Status }; }); + int rowsInserted = await dbContext.BulkInsertAsync(orders, options => + { + options.UsePermanentTable = true; + options.InputColumns = o => new { o.Price, o.Active, o.AddedDateTime, o.Status }; + }); int newTotal = dbContext.Orders.Where(o => o.Price == 1.57M && o.ExternalId == null && o.Active == true).Count(); Assert.IsTrue(rowsInserted == orders.Count, "The number of rows inserted must match the count of order list"); @@ -398,4 +401,4 @@ public async Task With_ValueGenerated_Computed() Assert.IsTrue(newTotal - oldTotal == rowsInserted, "The new count minus the old count should match the number of rows inserted."); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMerge.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMerge.cs index 3b99e31..f1c75d9 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMerge.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMerge.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -24,7 +24,7 @@ public void With_Default_Options() { orders.Add(new Order { Id = 100000 + i, Price = 3.55M }); } - var result = dbContext.BulkMerge(orders, o => o.UsePermanentTable=true); + var result = dbContext.BulkMerge(orders, o => o.UsePermanentTable = true); var newOrders = dbContext.Orders.OrderBy(o => o.Id).ToList(); bool areAddedOrdersMerged = true; bool areUpdatedOrdersMerged = true; @@ -327,7 +327,7 @@ public void With_ValueGenerated_Default() } int oldTotal = dbContext.Orders.Where(o => o.DbAddedDateTime > nowDateTime).Count(); var mergeResult = dbContext.BulkMerge(orders); - int newTotal = dbContext.Orders.Where(o => o.Price <= 1.57M + int newTotal = dbContext.Orders.Where(o => o.Price <= 1.57M && o.DbAddedDateTime > nowDateTime).Count(); Assert.IsTrue(mergeResult.RowsInserted == orders.Count, "The number of rows inserted must match the count of order list"); @@ -351,4 +351,4 @@ public void With_ValueGenerated_Computed() Assert.IsTrue(newTotal - oldTotal == result.RowsInserted, "The new count minus the old count should match the number of rows inserted."); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMergeAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMergeAsync.cs index ebdd81c..e7d9a42 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMergeAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkMergeAsync.cs @@ -1,9 +1,9 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -360,7 +360,7 @@ public async Task With_Merge_On_Enum() var orders = new List(); for (int i = 0; i < 20; i++) { - orders.Add(new Order { Id = i, Price = 1.57M, DbModifiedDateTime = nowDateTime, Status = OrderStatus.Completed}); + orders.Add(new Order { Id = i, Price = 1.57M, DbModifiedDateTime = nowDateTime, Status = OrderStatus.Completed }); } var result = await dbContext.BulkMergeAsync(orders, options => options.MergeOnCondition = (s, t) => s.Id == t.Id && s.Status == t.Status); diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChanges.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChanges.cs index 3cca637..139c36a 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChanges.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChanges.cs @@ -1,11 +1,11 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -121,7 +121,7 @@ public void With_Inheritance_Tpc() //Add New Customers long maxId = dbContext.TpcPeople.OfType().Max(o => o.Id); int expectedRowsAdded = 3000; - for (long i = maxId+1; i <= maxId+expectedRowsAdded; i++) + for (long i = maxId + 1; i <= maxId + expectedRowsAdded; i++) { dbContext.TpcPeople.Add(new TpcCustomer { @@ -261,4 +261,4 @@ public void With_Schema() Assert.IsTrue(productsUpdatedCount == productsToUpdate.Count(), "The number of products that was updated did not match what was expected."); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChangesAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChangesAsync.cs index 43fbc72..9b31633 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChangesAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSaveChangesAsync.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -32,7 +32,7 @@ public async Task With_All_Changes() //Update existing orders var ordersToUpdate = dbContext.Orders.Where(o => o.Price > 5 && o.Price <= 10).ToList(); - foreach(var orderToUpdate in ordersToUpdate) + foreach (var orderToUpdate in ordersToUpdate) { orderToUpdate.Price = 99M; } @@ -261,4 +261,4 @@ public async Task with_Schema() Assert.IsTrue(productsUpdatedCount == productsToUpdate.Count(), "The number of products that was updated did not match what was expected."); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSync.cs index 3a7e2ab..61c6f95 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSync.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -239,4 +239,4 @@ public void With_Options_MergeOnCondition() Assert.IsTrue(areUpdatedOrdersMerged, "The orders that were updated did not merge correctly"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSyncAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSyncAsync.cs index b384559..9f10205 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSyncAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkSyncAsync.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -241,4 +241,4 @@ public async Task With_Options_MergeOnCondition() Assert.IsTrue(areUpdatedOrdersMerged, "The orders that were updated did not merge correctly"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdate.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdate.cs index 6f6aeeb..028d462 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdate.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdate.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using Microsoft.VisualStudio.TestTools.UnitTesting; using N.EntityFrameworkCore.Extensions.Test.Data; -using System; -using System.Collections.Generic; -using System.Linq; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -244,4 +244,4 @@ public void With_Transaction() Assert.IsTrue(rollbackTotal == orders.Count, "The number of rows after the transacation has been rollbacked should match the original count"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdateAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdateAsync.cs index 022ce97..a928090 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdateAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/BulkUpdateAsync.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -243,4 +243,4 @@ public async Task With_Transaction() Assert.IsTrue(rollbackTotal == orders.Count, "The number of rows after the transacation has been rollbacked should match the original count"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DbContextExtensionsBase.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DbContextExtensionsBase.cs index 2bbf649..bd2b77a 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DbContextExtensionsBase.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DbContextExtensionsBase.cs @@ -1,11 +1,11 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using N.EntityFrameworkCore.Extensions.Test.Data.Enums; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; +using N.EntityFrameworkCore.Extensions.Test.Data.Enums; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -251,4 +251,4 @@ protected TestDbContext SetupDbContext(bool populateData, PopulateDataMode mode return dbContext; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQuery.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQuery.cs index 4c6bf45..79c40f4 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQuery.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQuery.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -146,4 +146,4 @@ public void With_Transaction() Assert.IsTrue(newTotal == oldTotal, "The new count must match the old count since the transaction was rollbacked"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQueryAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQueryAsync.cs index 8f09a1a..fec1b20 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQueryAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/DeleteFromQueryAsync.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -147,4 +147,4 @@ public async Task With_Transaction() Assert.IsTrue(newTotal == oldTotal, "The new count must match the old count since the transaction was rollbacked"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/Fetch.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/Fetch.cs index ec4de87..5fec86d 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/Fetch.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/Fetch.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -175,4 +175,4 @@ public void With_Options_InputColumns() Assert.IsTrue(expectedBatchCount == batchCount, "The total number of batches fetched must match what is expected"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/FetchAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/FetchAsync.cs index 0c9b8fa..c854bcd 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/FetchAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/FetchAsync.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -74,7 +74,8 @@ public async Task With_DateTime() await orders.FetchAsync(async result => { - await Task.Run(() => { + await Task.Run(() => + { batchCount++; totalCount += result.Results.Count; Assert.IsTrue(result.Results.Count <= batchSize, "The count of results in each batch callback should less than or equal to the batchSize"); @@ -190,4 +191,4 @@ await Task.Run(() => Assert.IsTrue(expectedBatchCount == batchCount, "The total number of batches fetched must match what is expected"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQuery.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQuery.cs index bc303bc..a933051 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQuery.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQuery.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -68,4 +68,4 @@ public void With_Transaction() Assert.IsFalse(tableExistsAfter, string.Format("Table {0} should not exist after transaction rollback", tableName)); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQueryAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQueryAsync.cs index 73edfc9..2eeb8f9 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQueryAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/InsertFromQueryAsync.cs @@ -1,8 +1,8 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -37,7 +37,7 @@ public async Task With_Decimal_Value() string tableName = "OrdersUnderTen"; var orders = dbContext.Orders.Where(o => o.Price < 10M); int oldSourceTotal = orders.Count(); - int rowsInserted = await dbContext .Orders.Where(o => o.Price < 10M).InsertFromQueryAsync(tableName, o => new { o.Id, o.Price, o.AddedDateTime, o.Active }); + int rowsInserted = await dbContext.Orders.Where(o => o.Price < 10M).InsertFromQueryAsync(tableName, o => new { o.Id, o.Price, o.AddedDateTime, o.Active }); int newSourceTotal = orders.Count(); int newTargetTotal = orders.UsingTable(tableName).Count(); @@ -86,4 +86,4 @@ public async Task With_Transaction() Assert.IsFalse(tableExistsAfter, string.Format("Table {0} should not exist after transaction rollback", tableName)); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFile.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFile.cs index 21523a0..78b5265 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFile.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFile.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.IO; +using System.IO; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -45,4 +45,4 @@ public void Using_FileStream() Assert.IsTrue(queryToCsvFileResult.TotalRowCount == count + 1, "The total number of rows written to the file should match the count from the database plus the header row"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFileAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFileAsync.cs index 3f62755..bab8164 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFileAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/QueryToCsvFileAsync.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.IO; +using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -46,4 +46,4 @@ public async Task Using_FileStream() Assert.IsTrue(queryToCsvFileResult.TotalRowCount == count + 1, "The total number of rows written to the file should match the count from the database plus the header row"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQuery.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQuery.cs index 179627b..b2fa7f6 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQuery.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQuery.cs @@ -1,12 +1,12 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using N.EntityFrameworkCore.Extensions.Test.Data.Enums; -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; +using N.EntityFrameworkCore.Extensions.Test.Data.Enums; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -274,4 +274,4 @@ public void With_Variable_And_Decimal() Assert.IsTrue(newTotal == 0, "The new count must be 0 to indicate all records were updated"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQueryAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQueryAsync.cs index 4dfcbcb..ba7ca2e 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQueryAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbContextExtensions/UpdateFromQueryAsync.cs @@ -1,13 +1,13 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using N.EntityFrameworkCore.Extensions.Test.Data; -using N.EntityFrameworkCore.Extensions.Test.Data.Enums; -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using N.EntityFrameworkCore.Extensions.Test.Data; +using N.EntityFrameworkCore.Extensions.Test.Data.Enums; namespace N.EntityFrameworkCore.Extensions.Test.DbContextExtensions { @@ -275,4 +275,4 @@ public async Task With_Variable_And_Decimal() Assert.IsTrue(newTotal == 0, "The new count must be 0 to indicate all records were updated"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Clear.cs b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Clear.cs index 902b1ff..e344c39 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Clear.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Clear.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; using N.EntityFrameworkCore.Extensions.Test.Data; using N.EntityFrameworkCore.Extensions.Test.DbContextExtensions; -using System.Linq; namespace N.EntityFrameworkCore.Extensions.Test.DbSetExtensions { @@ -20,4 +20,4 @@ public void Using_Dbset() Assert.IsTrue(newOrdersCount == 0, "Order table should be empty after truncating"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/ClearAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/ClearAsync.cs index 1ba354f..921d654 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/ClearAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/ClearAsync.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; using N.EntityFrameworkCore.Extensions.Test.Data; using N.EntityFrameworkCore.Extensions.Test.DbContextExtensions; -using System.Linq; -using System.Threading.Tasks; namespace N.EntityFrameworkCore.Extensions.Test.DbSetExtensions { @@ -21,4 +21,4 @@ public async Task Using_Dbset() Assert.IsTrue(newOrdersCount == 0, "Order table should be empty after truncating"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Truncate.cs b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Truncate.cs index ffe8c56..9bcdc51 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Truncate.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/Truncate.cs @@ -1,7 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; using N.EntityFrameworkCore.Extensions.Test.Data; using N.EntityFrameworkCore.Extensions.Test.DbContextExtensions; -using System.Linq; namespace N.EntityFrameworkCore.Extensions.Test.DbSetExtensions { @@ -20,4 +20,4 @@ public void Using_Dbset() Assert.IsTrue(newOrdersCount == 0, "Order table should be empty after truncating"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/TruncateAsync.cs b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/TruncateAsync.cs index 01a52a6..5d3a1ad 100644 --- a/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/TruncateAsync.cs +++ b/N.EntityFrameworkCore.Extensions.Test/DbSetExtensions/TruncateAsync.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; using N.EntityFrameworkCore.Extensions.Test.Data; using N.EntityFrameworkCore.Extensions.Test.DbContextExtensions; -using System.Linq; -using System.Threading.Tasks; namespace N.EntityFrameworkCore.Extensions.Test.DbSetExtensions { @@ -21,4 +21,4 @@ public async Task Using_Dbset() Assert.IsTrue(newOrdersCount == 0, "Order table should be empty after truncating"); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.Test/LinqExtensions/ToSqlPredicateTests.cs b/N.EntityFrameworkCore.Extensions.Test/LinqExtensions/ToSqlPredicateTests.cs index 26b37a0..a666cec 100644 --- a/N.EntityFrameworkCore.Extensions.Test/LinqExtensions/ToSqlPredicateTests.cs +++ b/N.EntityFrameworkCore.Extensions.Test/LinqExtensions/ToSqlPredicateTests.cs @@ -14,9 +14,9 @@ public void Should_handle_int() var sqlPredicate = expression.ToSqlPredicate("s", "t"); - Assert.AreEqual("s.Id = t.Id",sqlPredicate); + Assert.AreEqual("s.Id = t.Id", sqlPredicate); } - + [TestMethod] public void Should_handle_enum() { @@ -24,7 +24,7 @@ public void Should_handle_enum() var sqlPredicate = expression.ToSqlPredicate("s", "t"); - Assert.AreEqual("s.Type = t.Type",sqlPredicate); + Assert.AreEqual("s.Type = t.Type", sqlPredicate); } [TestMethod] @@ -49,7 +49,7 @@ public void Should_handle_prop_naming() Assert.AreEqual("s.Id = t.Id AND s.ExternalId = t.ExternalId", sqlPredicate); } - + record Entity { public Guid Id { get; set; } @@ -63,4 +63,4 @@ enum EntityType Two, Three } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions.sln b/N.EntityFrameworkCore.Extensions.sln index 2db0e37..a4685a5 100644 --- a/N.EntityFrameworkCore.Extensions.sln +++ b/N.EntityFrameworkCore.Extensions.sln @@ -1,12 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30225.117 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.34929.205 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N.EntityFrameworkCore.Extensions", "N.EntityFrameworkCore.Extensions\N.EntityFrameworkCore.Extensions.csproj", "{EBFA8667-BB63-41C0-A5BA-E41CA2B553E8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N.EntityFrameworkCore.Extensions.Test", "N.EntityFrameworkCore.Extensions.Test\N.EntityFrameworkCore.Extensions.Test.csproj", "{A52CDEFF-F507-4EA2-B5B1-AE46A3AFCE95}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A169187F-E5B6-4C2D-AB86-7B92B05D27C0}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/N.EntityFrameworkCore.Extensions/Common/Constants.cs b/N.EntityFrameworkCore.Extensions/Common/Constants.cs index dc5443b..45602a0 100644 --- a/N.EntityFrameworkCore.Extensions/Common/Constants.cs +++ b/N.EntityFrameworkCore.Extensions/Common/Constants.cs @@ -10,4 +10,4 @@ public static class Constants { public readonly static string InternalId_ColumnName = "_be_xx_id"; } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkFetchOptions.cs b/N.EntityFrameworkCore.Extensions/Data/BulkFetchOptions.cs index 9781e6e..684ad2d 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkFetchOptions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkFetchOptions.cs @@ -18,4 +18,4 @@ public BulkFetchOptions() //this.ConnectionBehavior = ConnectionBehavior.New; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkInsertOptions.cs b/N.EntityFrameworkCore.Extensions/Data/BulkInsertOptions.cs index 87690b1..da8f863 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkInsertOptions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkInsertOptions.cs @@ -13,7 +13,7 @@ public class BulkInsertOptions : BulkOptions public bool InsertIfNotExists { get; set; } public Expression> InsertOnCondition { get; set; } public bool KeepIdentity { get; set; } - + public string[] GetInputColumns() { return this.InputColumns == null ? null : this.InputColumns.Body.Type.GetProperties().Select(o => o.Name).ToArray(); diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkMergeOption.cs b/N.EntityFrameworkCore.Extensions/Data/BulkMergeOption.cs index 1cb720a..e7cc0cd 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkMergeOption.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkMergeOption.cs @@ -29,4 +29,4 @@ public List GetIgnoreColumnsOnUpdate() return this.IgnoreColumnsOnUpdate == null ? new List() : this.IgnoreColumnsOnUpdate.Body.Type.GetProperties().Select(o => o.Name).ToList(); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkMergeResult.cs b/N.EntityFrameworkCore.Extensions/Data/BulkMergeResult.cs index 7be0f28..42e3a9e 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkMergeResult.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkMergeResult.cs @@ -1,5 +1,5 @@ -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace N.EntityFrameworkCore.Extensions { diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkOperation.cs b/N.EntityFrameworkCore.Extensions/Data/BulkOperation.cs index 10b99ab..0e4eb4b 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkOperation.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkOperation.cs @@ -1,13 +1,4 @@ -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Conventions; -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.Extensions.Options; -using N.EntityFrameworkCore.Extensions.Common; -using N.EntityFrameworkCore.Extensions.Sql; -using N.EntityFrameworkCore.Extensions.Util; -using System; +using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel.Design; @@ -18,6 +9,15 @@ using System.Linq.Expressions; using System.Reflection; using System.Transactions; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.Extensions.Options; +using N.EntityFrameworkCore.Extensions.Common; +using N.EntityFrameworkCore.Extensions.Sql; +using N.EntityFrameworkCore.Extensions.Util; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace N.EntityFrameworkCore.Extensions @@ -37,7 +37,7 @@ internal partial class BulkOperation : IDisposable internal SqlTransaction Transaction => DbTransactionContext.CurrentTransaction; internal TableMapping TableMapping { get; } internal IEnumerable SchemaQualifiedTableNames => TableMapping.GetSchemaQualifiedTableNames(); - + public BulkOperation(DbContext dbContext, BulkOptions options, Expression> inputColumns = null, Expression> ignoreColumns = null) { @@ -51,7 +51,7 @@ public BulkOperation(DbContext dbContext, BulkOptions options, Expression BulkInsertStagingData(IEnumerable entities, bool keepIdentity=true, bool useInternalId=false) + internal BulkInsertResult BulkInsertStagingData(IEnumerable entities, bool keepIdentity = true, bool useInternalId = false) { IEnumerable columnsToInsert = GetColumnNames(keepIdentity); string internalIdColumn = useInternalId ? Common.Constants.InternalId_ColumnName : null; @@ -59,7 +59,7 @@ internal BulkInsertResult BulkInsertStagingData(IEnumerable entities, bool StagingTableCreated = true; return DbContextExtensions.BulkInsert(entities, Options, TableMapping, Connection, Transaction, StagingTableName, columnsToInsert, SqlBulkCopyOptions.KeepIdentity, useInternalId); } - internal BulkMergeResult ExecuteMerge(Dictionary entityMap, Expression> mergeOnCondition, + internal BulkMergeResult ExecuteMerge(Dictionary entityMap, Expression> mergeOnCondition, bool autoMapOutput, bool keepIdentity, bool insertIfNotExists, bool update = false, bool delete = false) { var rowsInserted = new Dictionary(); @@ -88,10 +88,10 @@ internal BulkMergeResult ExecuteMerge(Dictionary entityMap, Expressi if (autoMapOutput) { - List allProperties = + List allProperties = [ - ..TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAdd).ToArray(), - ..TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAddOrUpdate).ToArray() + .. TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAdd).ToArray(), + .. TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAddOrUpdate).ToArray() ]; var bulkQueryResult = Context.BulkQuery(mergeStatement.Sql, Options); @@ -165,7 +165,7 @@ internal int ExecuteUpdate(IEnumerable entities, Expression> IEnumerable columnstoUpdate = CommonUtil.FormatColumns(GetColumnNames(entityType)); string updateSetExpression = string.Join(",", columnstoUpdate.Select(o => string.Format("t.{0}=s.{0}", o))); string updateSql = string.Format("UPDATE t SET {0} FROM {1} AS s JOIN {2} AS t ON {3}; SELECT @@RowCount;", - updateSetExpression, StagingTableName, CommonUtil.FormatTableName(entityType.GetSchemaQualifiedTableName()), + updateSetExpression, StagingTableName, CommonUtil.FormatTableName(entityType.GetSchemaQualifiedTableName()), CommonUtil.GetJoinConditionSql(updateOnCondition, PrimaryKeyColumnNames, "s", "t")); rowsUpdated = Context.Database.ExecuteSqlInternal(updateSql, Options.CommandTimeout); } @@ -186,7 +186,7 @@ internal void ValidateBulkUpdate(Expression> updateOnCondition) } public void Dispose() { - if(StagingTableCreated) + if (StagingTableCreated) { Context.Database.DropTable(StagingTableName); } @@ -200,4 +200,4 @@ internal IEnumerable GetColumnNames(IEntityType entityType, bool includP return CommonUtil.FilterColumns(TableMapping.GetColumnNames(entityType, includPrimaryKeys), PrimaryKeyColumnNames, InputColumns, IgnoreColumns); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkOperationAsync.cs b/N.EntityFrameworkCore.Extensions/Data/BulkOperationAsync.cs index d06b573..8e4b704 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkOperationAsync.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkOperationAsync.cs @@ -1,14 +1,14 @@ -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using N.EntityFrameworkCore.Extensions.Sql; -using N.EntityFrameworkCore.Extensions.Util; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using N.EntityFrameworkCore.Extensions.Sql; +using N.EntityFrameworkCore.Extensions.Util; namespace N.EntityFrameworkCore.Extensions { @@ -22,7 +22,7 @@ internal async Task> BulkInsertStagingDataAsync(IEnumerable< StagingTableCreated = true; return await DbContextExtensionsAsync.BulkInsertAsync(entities, Options, TableMapping, Connection, Transaction, StagingTableName, columnsToInsert, SqlBulkCopyOptions.KeepIdentity, useInternalId, cancellationToken); } - + internal async Task> ExecuteMergeAsync(Dictionary entityMap, Expression> mergeOnCondition, bool autoMapOutput, bool insertIfNotExists, bool update = false, bool delete = false, CancellationToken cancellationToken = default) { @@ -51,12 +51,12 @@ internal async Task> ExecuteMergeAsync(Dictionary en if (autoMapOutput) { - List allProperties = + List allProperties = [ - ..TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAdd).ToArray(), - ..TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAddOrUpdate).ToArray() + .. TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAdd).ToArray(), + .. TableMapping.GetEntityProperties(entityType, ValueGenerated.OnAddOrUpdate).ToArray() ]; - + var bulkQueryResult = await Context.BulkQueryAsync(mergeStatement.Sql, Connection, Transaction, Options, cancellationToken); rowsAffected[entityType] = bulkQueryResult.RowsAffected; @@ -116,11 +116,11 @@ internal async Task ExecuteUpdateAsync(IEnumerable entities, Expression< IEnumerable columnstoUpdate = CommonUtil.FormatColumns(GetColumnNames(entityType)); string updateSetExpression = string.Join(",", columnstoUpdate.Select(o => string.Format("t.{0}=s.{0}", o))); string updateSql = string.Format("UPDATE t SET {0} FROM {1} AS s JOIN {2} AS t ON {3}; SELECT @@RowCount;", - updateSetExpression, StagingTableName, CommonUtil.FormatTableName(entityType.GetSchemaQualifiedTableName()), + updateSetExpression, StagingTableName, CommonUtil.FormatTableName(entityType.GetSchemaQualifiedTableName()), CommonUtil.GetJoinConditionSql(updateOnCondition, PrimaryKeyColumnNames, "s", "t")); rowsUpdated = await Context.Database.ExecuteSqlAsync(updateSql, Options.CommandTimeout, cancellationToken); } return rowsUpdated; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkOptions.cs b/N.EntityFrameworkCore.Extensions/Data/BulkOptions.cs index da7544e..69888f8 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkOptions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkOptions.cs @@ -1,11 +1,11 @@ -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore.Metadata; -using N.EntityFrameworkCore.Extensions.Enums; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore.Metadata; +using N.EntityFrameworkCore.Extensions.Enums; namespace N.EntityFrameworkCore.Extensions { @@ -32,4 +32,4 @@ public BulkOptions() this.ConnectionBehavior = ConnectionBehavior.Default; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkSyncOptions.cs b/N.EntityFrameworkCore.Extensions/Data/BulkSyncOptions.cs index 9fbd86e..83a1d72 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkSyncOptions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkSyncOptions.cs @@ -8,4 +8,4 @@ public BulkSyncOptions() this.DeleteIfNotMatched = true; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/BulkSyncResult.cs b/N.EntityFrameworkCore.Extensions/Data/BulkSyncResult.cs index 79a7a4b..6c06c30 100644 --- a/N.EntityFrameworkCore.Extensions/Data/BulkSyncResult.cs +++ b/N.EntityFrameworkCore.Extensions/Data/BulkSyncResult.cs @@ -16,4 +16,4 @@ public static BulkSyncResult Map(BulkMergeResult result) }; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensions.cs b/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensions.cs index 5c14845..8aae0e3 100644 --- a/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensions.cs @@ -1,17 +1,17 @@ -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; -using Microsoft.EntityFrameworkCore.Storage; -using N.EntityFrameworkCore.Extensions.Enums; -using N.EntityFrameworkCore.Extensions.Util; -using System; +using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Threading.Tasks; using System.Transactions; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; +using Microsoft.EntityFrameworkCore.Storage; +using N.EntityFrameworkCore.Extensions.Enums; +using N.EntityFrameworkCore.Extensions.Util; namespace N.EntityFrameworkCore.Extensions { @@ -33,7 +33,7 @@ internal static int CloneTable(this DatabaseFacade database, IEnumerable { string columns = columnNames != null && columnNames.Count() > 0 ? string.Join(",", CommonUtil.FormatColumns(columnNames)) : "*"; columns = !string.IsNullOrEmpty(internalIdColumnName) ? string.Format("{0},CAST( NULL AS INT) AS {1}", columns, internalIdColumnName) : columns; - return database.ExecuteSqlRaw(string.Format("SELECT TOP 0 {0} INTO {1} FROM {2}", columns, destinationTable, string.Join(",",sourceTables))); + return database.ExecuteSqlRaw(string.Format("SELECT TOP 0 {0} INTO {1} FROM {2}", columns, destinationTable, string.Join(",", sourceTables))); } internal static DbCommand CreateCommand(this DatabaseFacade database, ConnectionBehavior connectionBehavior = ConnectionBehavior.Default) { @@ -41,12 +41,12 @@ internal static DbCommand CreateCommand(this DatabaseFacade database, Connection if (dbConnection.State != ConnectionState.Open) dbConnection.Open(); var command = dbConnection.CreateCommand(); - if(database.CurrentTransaction != null && connectionBehavior == ConnectionBehavior.Default) + if (database.CurrentTransaction != null && connectionBehavior == ConnectionBehavior.Default) command.Transaction = database.CurrentTransaction.GetDbTransaction(); return command; } - public static int DropTable(this DatabaseFacade database, string tableName, bool ifExists = false) + public static int DropTable(this DatabaseFacade database, string tableName, bool ifExists = false) { bool deleteTable = !ifExists || (ifExists && database.TableExists(tableName)) ? true : false; return deleteTable ? database.ExecuteSqlInternal(string.Format("DROP TABLE {0}", tableName), null, ConnectionBehavior.Default) : -1; @@ -79,7 +79,7 @@ internal static int ExecuteSql(this DatabaseFacade database, string sql, object[ { command.CommandTimeout = commandTimeout.Value; } - if(parameters != null) + if (parameters != null) { command.Parameters.AddRange(parameters); } @@ -118,5 +118,4 @@ internal static DbConnection GetDbConnection(this DatabaseFacade database, Conne return connectionBehavior == ConnectionBehavior.New ? ((ICloneable)database.GetDbConnection()).Clone() as DbConnection : database.GetDbConnection(); } } -} - +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensionsAsync.cs b/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensionsAsync.cs index 29dcdc1..7b9ca28 100644 --- a/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensionsAsync.cs +++ b/N.EntityFrameworkCore.Extensions/Data/DatabaseFacadeExtensionsAsync.cs @@ -1,14 +1,14 @@ -using Microsoft.Data.SqlClient; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; using N.EntityFrameworkCore.Extensions.Util; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using System.Linq; -using System.Data; -using System; namespace N.EntityFrameworkCore.Extensions { @@ -81,5 +81,4 @@ internal async static Task ToggleIdentityInsertAsync(this DatabaseFacade databas } } } -} - +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/DbContextExtensions.cs b/N.EntityFrameworkCore.Extensions/Data/DbContextExtensions.cs index a8266e4..8d9e6d8 100644 --- a/N.EntityFrameworkCore.Extensions/Data/DbContextExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/DbContextExtensions.cs @@ -1,4 +1,15 @@ -using Microsoft.Data.SqlClient; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Data.Common; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; @@ -16,17 +27,6 @@ using N.EntityFrameworkCore.Extensions.Extensions; using N.EntityFrameworkCore.Extensions.Sql; using N.EntityFrameworkCore.Extensions.Util; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Data.Common; -using System.IO; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace N.EntityFrameworkCore.Extensions @@ -86,16 +86,16 @@ public static int BulkDelete(this DbContext context, IEnumerable entities, } return rowsAffected; } - } - public static IEnumerable BulkFetch(this DbSet dbSet, IEnumerable entities) where T : class, new() + } + public static IEnumerable BulkFetch(this DbSet dbSet, IEnumerable entities) where T : class, new() { return dbSet.BulkFetch(entities, new BulkFetchOptions()); } - public static IEnumerable BulkFetch(this DbSet dbSet, IEnumerable entities, Action> optionsAction) where T : class, new() + public static IEnumerable BulkFetch(this DbSet dbSet, IEnumerable entities, Action> optionsAction) where T : class, new() { return dbSet.BulkFetch(entities, optionsAction.Build()); } - public static IEnumerable BulkFetch(this DbSet dbSet, IEnumerable entities, BulkFetchOptions options) where T : class, new() + public static IEnumerable BulkFetch(this DbSet dbSet, IEnumerable entities, BulkFetchOptions options) where T : class, new() { var context = dbSet.GetDbContext(); var tableMapping = context.GetTableMapping(typeof(T)); @@ -210,7 +210,7 @@ private static void Validate(TableMapping tableMapping) var entity = reader.MapEntity(dbContext, properties, valuesFromProvider); yield return entity; } - + reader.Close(); } public static int BulkInsert(this DbContext context, IEnumerable entities) @@ -229,7 +229,7 @@ public static int BulkInsert(this DbContext context, IEnumerable entities, try { var bulkInsertResult = bulkOperation.BulkInsertStagingData(entities, true, true); - var bulkMergeResult = bulkOperation.ExecuteMerge(bulkInsertResult.EntityMap, options.InsertOnCondition, + var bulkMergeResult = bulkOperation.ExecuteMerge(bulkInsertResult.EntityMap, options.InsertOnCondition, options.AutoMapOutput, options.KeepIdentity, options.InsertIfNotExists); rowsAffected = bulkMergeResult.RowsAffected; bulkOperation.DbTransactionContext.Commit(); @@ -247,15 +247,15 @@ internal static void SetStoreGeneratedValues(this DbContext context, T entity { int index = 0; var updateEntry = entity as InternalEntityEntry; - if(updateEntry == null) + if (updateEntry == null) { var entry = context.Entry(entity); updateEntry = entry.GetInfrastructure(); } - if(updateEntry != null) + if (updateEntry != null) { - foreach(var property in properties) + foreach (var property in properties) { if (!property.IsPrimaryKey() || (property.IsPrimaryKey() && updateEntry.EntityState == EntityState.Detached)) @@ -271,7 +271,7 @@ internal static void SetStoreGeneratedValues(this DbContext context, T entity } index++; } - if(updateEntry.EntityState == EntityState.Detached) + if (updateEntry.EntityState == EntityState.Detached) updateEntry.AcceptChanges(); } else @@ -337,7 +337,7 @@ public static int BulkSaveChanges(this DbContext dbContext) { return dbContext.BulkSaveChanges(true); } - public static int BulkSaveChanges(this DbContext dbContext, bool acceptAllChangesOnSuccess=true) + public static int BulkSaveChanges(this DbContext dbContext, bool acceptAllChangesOnSuccess = true) { int rowsAffected = 0; var stateManager = dbContext.GetDependencies().StateManager; @@ -363,8 +363,8 @@ public static int BulkSaveChanges(this DbContext dbContext, bool acceptAllChange rowsAffected += dbContext.BulkDelete(entities, o => { o.EntityType = key.EntityType; }); } } - - if(acceptAllChangesOnSuccess) + + if (acceptAllChangesOnSuccess) dbContext.ChangeTracker.AcceptAllChanges(); return rowsAffected; @@ -490,7 +490,7 @@ public static int DeleteFromQuery(this IQueryable querable, int? commandTi { var sqlQuery = SqlBuilder.Parse(querable.ToQueryString()); sqlQuery.ChangeToDelete(); - rowAffected = dbContext.Database.ExecuteSql(sqlQuery.Sql, sqlQuery.Parameters.ToArray()); + rowAffected = dbContext.Database.ExecuteSql(sqlQuery.Sql, sqlQuery.Parameters.ToArray()); dbTransactionContext.Commit(); } @@ -746,5 +746,4 @@ public static TableMapping GetTableMapping(this DbContext dbContext, Type type, return new TableMapping(dbContext, entityType); } } -} - +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/DbContextExtensionsAsync.cs b/N.EntityFrameworkCore.Extensions/Data/DbContextExtensionsAsync.cs index 245159a..017f451 100644 --- a/N.EntityFrameworkCore.Extensions/Data/DbContextExtensionsAsync.cs +++ b/N.EntityFrameworkCore.Extensions/Data/DbContextExtensionsAsync.cs @@ -1,4 +1,13 @@ -using Microsoft.Data.SqlClient; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -10,15 +19,6 @@ using N.EntityFrameworkCore.Extensions.Extensions; using N.EntityFrameworkCore.Extensions.Sql; using N.EntityFrameworkCore.Extensions.Util; -using System; -using System.Collections.Generic; -using System.Data; -using System.IO; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; namespace N.EntityFrameworkCore.Extensions { @@ -52,7 +52,7 @@ public async static Task BulkDeleteAsync(this DbContext context, IEnumer throw new InvalidDataException("BulkDelete requires that the entity have a primary key or the Options.DeleteOnCondition must be set."); await context.Database.CloneTableAsync(destinationTableName, stagingTableName, keyColumnNames, null, cancellationToken); - await BulkInsertAsync(entities, options, tableMapping, dbConnection, transaction, stagingTableName, keyColumnNames, SqlBulkCopyOptions.KeepIdentity, + await BulkInsertAsync(entities, options, tableMapping, dbConnection, transaction, stagingTableName, keyColumnNames, SqlBulkCopyOptions.KeepIdentity, false, cancellationToken); string deleteSql = string.Format("DELETE t FROM {0} s JOIN {1} t ON {2}", stagingTableName, destinationTableName, CommonUtil.GetJoinConditionSql(options.DeleteOnCondition, keyColumnNames)); @@ -68,11 +68,11 @@ await BulkInsertAsync(entities, options, tableMapping, dbConnection, transaction return rowsAffected; } } - public async static Task FetchAsync(this IQueryable querable, Func,Task> action, Action> optionsAction, CancellationToken cancellationToken = default) where T : class, new() + public async static Task FetchAsync(this IQueryable querable, Func, Task> action, Action> optionsAction, CancellationToken cancellationToken = default) where T : class, new() { await FetchAsync(querable, action, optionsAction.Build(), cancellationToken); } - public async static Task FetchAsync(this IQueryable querable, Func,Task> action, FetchOptions options, CancellationToken cancellationToken = default) where T : class, new() + public async static Task FetchAsync(this IQueryable querable, Func, Task> action, FetchOptions options, CancellationToken cancellationToken = default) where T : class, new() { var dbContext = querable.GetDbContext(); var sqlQuery = SqlBuilder.Parse(querable.ToQueryString()); @@ -114,7 +114,7 @@ await BulkInsertAsync(entities, options, tableMapping, dbConnection, transaction if (entities.Count > 0) await action(new FetchResult { Results = entities, Batch = batch }); - + await reader.CloseAsync(); } public async static Task BulkInsertAsync(this DbContext context, IEnumerable entities, CancellationToken cancellationToken = default) @@ -349,7 +349,7 @@ public async static Task DeleteFromQueryAsync(this IQueryable querabl } return rowAffected; } - public async static Task InsertFromQueryAsync(this IQueryable querable, string tableName, Expression> insertObjectExpression, int? commandTimeout = null, + public async static Task InsertFromQueryAsync(this IQueryable querable, string tableName, Expression> insertObjectExpression, int? commandTimeout = null, CancellationToken cancellationToken = default) where T : class { int rowAffected = 0; @@ -384,7 +384,7 @@ public async static Task InsertFromQueryAsync(this IQueryable querabl } return rowAffected; } - public async static Task UpdateFromQueryAsync(this IQueryable querable, Expression> updateExpression, int? commandTimeout = null, + public async static Task UpdateFromQueryAsync(this IQueryable querable, Expression> updateExpression, int? commandTimeout = null, CancellationToken cancellationToken = default) where T : class { int rowAffected = 0; @@ -417,38 +417,38 @@ public async static Task QueryToCsvFileAsync(this IQueryab { return await QueryToCsvFileAsync(querable, stream, new QueryToFileOptions(), cancellationToken); } - public async static Task QueryToCsvFileAsync(this IQueryable querable, String filePath, Action optionsAction, + public async static Task QueryToCsvFileAsync(this IQueryable querable, String filePath, Action optionsAction, CancellationToken cancellationToken = default) where T : class { return await QueryToCsvFileAsync(querable, filePath, optionsAction.Build(), cancellationToken); } - public async static Task QueryToCsvFileAsync(this IQueryable querable, Stream stream, Action optionsAction, + public async static Task QueryToCsvFileAsync(this IQueryable querable, Stream stream, Action optionsAction, CancellationToken cancellationToken = default) where T : class { return await QueryToCsvFileAsync(querable, stream, optionsAction.Build(), cancellationToken); } - public async static Task QueryToCsvFileAsync(this IQueryable querable, String filePath, QueryToFileOptions options, + public async static Task QueryToCsvFileAsync(this IQueryable querable, String filePath, QueryToFileOptions options, CancellationToken cancellationToken = default) where T : class { var fileStream = File.Create(filePath); return await QueryToCsvFileAsync(querable, fileStream, options, cancellationToken); } - public async static Task QueryToCsvFileAsync(this IQueryable querable, Stream stream, QueryToFileOptions options, + public async static Task QueryToCsvFileAsync(this IQueryable querable, Stream stream, QueryToFileOptions options, CancellationToken cancellationToken = default) where T : class { return await InternalQueryToFileAsync(querable, stream, options, cancellationToken); } - public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, string filePath, string sqlText, object[] parameters, + public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, string filePath, string sqlText, object[] parameters, CancellationToken cancellationToken = default) { return await SqlQueryToCsvFileAsync(database, filePath, new QueryToFileOptions(), sqlText, parameters, cancellationToken); } - public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, Stream stream, string sqlText, object[] parameters, + public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, Stream stream, string sqlText, object[] parameters, CancellationToken cancellationToken = default) { return await SqlQueryToCsvFileAsync(database, stream, new QueryToFileOptions(), sqlText, parameters, cancellationToken); } - public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, string filePath, Action optionsAction, string sqlText, object[] parameters, + public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, string filePath, Action optionsAction, string sqlText, object[] parameters, CancellationToken cancellationToken = default) { return await SqlQueryToCsvFileAsync(database, filePath, optionsAction.Build(), sqlText, parameters, cancellationToken); @@ -458,13 +458,13 @@ public async static Task SqlQueryToCsvFileAsync(this Database { return await SqlQueryToCsvFileAsync(database, stream, optionsAction.Build(), sqlText, parameters, cancellationToken); } - public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, string filePath, QueryToFileOptions options, string sqlText, object[] parameters, + public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, string filePath, QueryToFileOptions options, string sqlText, object[] parameters, CancellationToken cancellationToken = default) { var fileStream = File.Create(filePath); return await SqlQueryToCsvFileAsync(database, fileStream, options, sqlText, parameters, cancellationToken); } - public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, Stream stream, QueryToFileOptions options, string sqlText, object[] parameters, + public async static Task SqlQueryToCsvFileAsync(this DatabaseFacade database, Stream stream, QueryToFileOptions options, string sqlText, object[] parameters, CancellationToken cancellationToken = default) { var dbConnection = database.GetDbConnection() as SqlConnection; @@ -482,7 +482,7 @@ public async static Task TruncateAsync(this DbSet dbSet, CancellationToken var tableMapping = dbContext.GetTableMapping(typeof(T)); await dbContext.Database.TruncateTableAsync(tableMapping.FullQualifedTableName, false, cancellationToken); } - private async static Task InternalQueryToFileAsync(this IQueryable querable, Stream stream, QueryToFileOptions options, + private async static Task InternalQueryToFileAsync(this IQueryable querable, Stream stream, QueryToFileOptions options, CancellationToken cancellationToken = default) where T : class { var dbContext = querable.GetDbContext(); @@ -560,4 +560,4 @@ private async static Task InternalQueryToFileAsync(SqlConnect }; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/DbTransactionContext.cs b/N.EntityFrameworkCore.Extensions/Data/DbTransactionContext.cs index 72b1f2b..49f3668 100644 --- a/N.EntityFrameworkCore.Extensions/Data/DbTransactionContext.cs +++ b/N.EntityFrameworkCore.Extensions/Data/DbTransactionContext.cs @@ -1,8 +1,8 @@ -using Microsoft.Data.SqlClient; +using System; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; using N.EntityFrameworkCore.Extensions.Enums; -using System; namespace N.EntityFrameworkCore.Extensions @@ -40,14 +40,14 @@ public DbTransactionContext(DbContext context, int? commandTimeout = null, Conne this.ownsTransaction = context.Database.CurrentTransaction == null; this.transaction = context.Database.CurrentTransaction; //?? context.Database.BeginTransaction(); this.defaultCommandTimeout = context.Database.GetCommandTimeout(); - if(this.transaction != null) + if (this.transaction != null) this.CurrentTransaction = transaction.GetDbTransaction() as SqlTransaction; } else { //this.CurrentTransaction = this.Connection.BeginTransaction(); } - + context.Database.SetCommandTimeout(commandTimeout); } @@ -67,8 +67,8 @@ internal void Commit() } internal void Rollback() { - if(this.transaction != null) + if (this.transaction != null) transaction.Rollback(); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommand.cs b/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommand.cs index b3c0300..da513e8 100644 --- a/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommand.cs +++ b/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommand.cs @@ -1,6 +1,6 @@ -using Microsoft.Data.SqlClient; +using System.Data.Common; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore.Diagnostics; -using System.Data.Common; namespace N.EntityFrameworkCore.Extensions { @@ -21,4 +21,4 @@ internal bool Execute(DbCommand command, CommandEventData eventData, Interceptio return true; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommandInterceptor.cs b/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommandInterceptor.cs index 931771b..4d09301 100644 --- a/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommandInterceptor.cs +++ b/N.EntityFrameworkCore.Extensions/Data/EfExtensionsCommandInterceptor.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore.Diagnostics; -using System; +using System; using System.Collections.Concurrent; using System.Data.Common; using System.Threading; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace N.EntityFrameworkCore.Extensions { @@ -27,4 +27,4 @@ internal void AddCommand(Guid clientConnectionId, EfExtensionsCommand efExtensio extensionCommands.TryAdd(clientConnectionId, efExtensionsCommand); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/EntityDataReader.cs b/N.EntityFrameworkCore.Extensions/Data/EntityDataReader.cs index 0e5444b..27c62f8 100644 --- a/N.EntityFrameworkCore.Extensions/Data/EntityDataReader.cs +++ b/N.EntityFrameworkCore.Extensions/Data/EntityDataReader.cs @@ -1,4 +1,9 @@ -using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Metadata; @@ -7,18 +12,13 @@ using Microsoft.EntityFrameworkCore.ValueGeneration; using N.EntityFrameworkCore.Extensions.Common; using N.EntityFrameworkCore.Extensions.Extensions; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Linq.Expressions; namespace N.EntityFrameworkCore.Extensions { internal class EntityDataReader : IDataReader { public TableMapping TableMapping { get; set; } - public Dictionary EntityMap { get; set; } + public Dictionary EntityMap { get; set; } private Dictionary columnIndexes; private int currentId; private bool useInternalId; @@ -39,7 +39,7 @@ public EntityDataReader(TableMapping tableMapping, IEnumerable entities, bool this.EntityMap = new Dictionary(); this.FieldCount = tableMapping.Properties.Length; this.TableMapping = tableMapping; - + int i = 0; foreach (var property in tableMapping.Properties) @@ -73,7 +73,7 @@ private Func GetValueSelector(IProperty property) } else { - if(property.DeclaringType is IComplexType complexType) + if (property.DeclaringType is IComplexType complexType) { selector = entry => entry.ComplexProperty(complexType.ComplexProperty).Property(property).CurrentValue; } @@ -210,7 +210,7 @@ public string GetString(int i) public object GetValue(int i) { - if(i == tableFieldCount) + if (i == tableFieldCount) { return this.currentId; } @@ -244,7 +244,7 @@ public bool NextResult() public bool Read() { bool moveNext = enumerator.MoveNext(); - + if (moveNext && this.useInternalId) { this.currentId++; @@ -253,5 +253,4 @@ public bool Read() return moveNext; } } -} - +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/FetchOptions.cs b/N.EntityFrameworkCore.Extensions/Data/FetchOptions.cs index 53632f4..f01d7e0 100644 --- a/N.EntityFrameworkCore.Extensions/Data/FetchOptions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/FetchOptions.cs @@ -13,4 +13,4 @@ public class FetchOptions public Expression> InputColumns { get; set; } public int BatchSize { get; set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/QueryToFileOptions.cs b/N.EntityFrameworkCore.Extensions/Data/QueryToFileOptions.cs index 0a43fc9..e7e3f13 100644 --- a/N.EntityFrameworkCore.Extensions/Data/QueryToFileOptions.cs +++ b/N.EntityFrameworkCore.Extensions/Data/QueryToFileOptions.cs @@ -20,4 +20,4 @@ public QueryToFileOptions() TextQualifer = ""; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/QueryToFileResult.cs b/N.EntityFrameworkCore.Extensions/Data/QueryToFileResult.cs index b97ee19..9f0aaf3 100644 --- a/N.EntityFrameworkCore.Extensions/Data/QueryToFileResult.cs +++ b/N.EntityFrameworkCore.Extensions/Data/QueryToFileResult.cs @@ -10,4 +10,4 @@ public class QueryToFileResult public int DataRowCount { get; internal set; } public int TotalRowCount { get; internal set; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/SqlMergeAction.cs b/N.EntityFrameworkCore.Extensions/Data/SqlMergeAction.cs index 19dabae..bfa75c0 100644 --- a/N.EntityFrameworkCore.Extensions/Data/SqlMergeAction.cs +++ b/N.EntityFrameworkCore.Extensions/Data/SqlMergeAction.cs @@ -12,4 +12,4 @@ internal static class SqlMergeAction public static string Update = "UPDATE"; public static string Delete = "DELETE"; } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/SqlQuery.cs b/N.EntityFrameworkCore.Extensions/Data/SqlQuery.cs index 0e95bda..3a75155 100644 --- a/N.EntityFrameworkCore.Extensions/Data/SqlQuery.cs +++ b/N.EntityFrameworkCore.Extensions/Data/SqlQuery.cs @@ -1,8 +1,8 @@ -using Microsoft.EntityFrameworkCore.Infrastructure; -using N.EntityFrameworkCore.Extensions.Sql; -using System; +using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Infrastructure; +using N.EntityFrameworkCore.Extensions.Sql; namespace N.EntityFrameworkCore.Extensions { @@ -34,4 +34,4 @@ public int ExecuteNonQuery() return database.ExecuteSql(this.SqlText, this.Parameters); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Data/TableMapping.cs b/N.EntityFrameworkCore.Extensions/Data/TableMapping.cs index 140afa2..11d3611 100644 --- a/N.EntityFrameworkCore.Extensions/Data/TableMapping.cs +++ b/N.EntityFrameworkCore.Extensions/Data/TableMapping.cs @@ -1,12 +1,12 @@ -using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using N.EntityFrameworkCore.Extensions.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; namespace N.EntityFrameworkCore.Extensions { @@ -160,5 +160,4 @@ internal IEnumerable GetSchemaQualifiedTableNames() .Select(o => $"[{o.GetSchema() ?? "dbo"}].[{o.GetTableName()}]").Distinct(); } } -} - +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Enums/ConnectionBehavior.cs b/N.EntityFrameworkCore.Extensions/Enums/ConnectionBehavior.cs index 298d083..b9b2563 100644 --- a/N.EntityFrameworkCore.Extensions/Enums/ConnectionBehavior.cs +++ b/N.EntityFrameworkCore.Extensions/Enums/ConnectionBehavior.cs @@ -11,4 +11,4 @@ internal enum ConnectionBehavior Default, New } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Enums/EfExtensionsCommandType.cs b/N.EntityFrameworkCore.Extensions/Enums/EfExtensionsCommandType.cs index 8f7d1d3..3b53e1a 100644 --- a/N.EntityFrameworkCore.Extensions/Enums/EfExtensionsCommandType.cs +++ b/N.EntityFrameworkCore.Extensions/Enums/EfExtensionsCommandType.cs @@ -10,4 +10,4 @@ enum EfExtensionsCommandType { ChangeTableName } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Extensions/CommonExtensions.cs b/N.EntityFrameworkCore.Extensions/Extensions/CommonExtensions.cs index 55f2fe7..bb03e58 100644 --- a/N.EntityFrameworkCore.Extensions/Extensions/CommonExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Extensions/CommonExtensions.cs @@ -13,4 +13,4 @@ internal static class CommonExtensions return parameter; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Extensions/DbDataReaderExtensions.cs b/N.EntityFrameworkCore.Extensions/Extensions/DbDataReaderExtensions.cs index b119018..4166106 100644 --- a/N.EntityFrameworkCore.Extensions/Extensions/DbDataReaderExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Extensions/DbDataReaderExtensions.cs @@ -1,13 +1,13 @@ -using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; -using Microsoft.EntityFrameworkCore.ChangeTracking; -using System; +using System; using System.Collections.Generic; using System.Data.Common; -using System.Reflection; using System.Linq; +using System.Reflection; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace N.EntityFrameworkCore.Extensions.Extensions; diff --git a/N.EntityFrameworkCore.Extensions/Extensions/IPropertyExtensions.cs b/N.EntityFrameworkCore.Extensions/Extensions/IPropertyExtensions.cs index bc7353e..05eb13d 100644 --- a/N.EntityFrameworkCore.Extensions/Extensions/IPropertyExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Extensions/IPropertyExtensions.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace N.EntityFrameworkCore.Extensions.Extensions { @@ -16,4 +16,4 @@ public static IEntityType GetDeclaringEntityType(this IProperty property) return property.DeclaringType as IEntityType; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Extensions/LinqExtensions.cs b/N.EntityFrameworkCore.Extensions/Extensions/LinqExtensions.cs index a1f99af..7e8b8ae 100644 --- a/N.EntityFrameworkCore.Extensions/Extensions/LinqExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Extensions/LinqExtensions.cs @@ -1,5 +1,4 @@ -using Microsoft.IdentityModel.Protocols; -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -9,6 +8,7 @@ using System.Text; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.IdentityModel.Protocols; namespace N.EntityFrameworkCore.Extensions { @@ -28,7 +28,7 @@ static class LinqExtensions internal static string ToSql(this MemberBinding binding) { - if(binding is MemberAssignment memberAssingment) + if (binding is MemberAssignment memberAssingment) { return GetExpressionValueAsString(memberAssingment.Expression); } @@ -143,7 +143,7 @@ internal static string ToSqlPredicate2(this Expression expression, params return sql; } - + static string ToSqlString(Expression expression, string sql = null) { sql ??= ""; @@ -190,7 +190,7 @@ internal static string ToSql(this Expression expression) { return $"{memberExpression}"; } - else if(expression is UnaryExpression unaryExpression) + else if (expression is UnaryExpression unaryExpression) { return $"{unaryExpression.Operand}"; } @@ -225,4 +225,4 @@ internal static string ToSqlUpdateSetExpression(this Expression expression return string.Join(",", setValues); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Extensions/ObjectExtensions.cs b/N.EntityFrameworkCore.Extensions/Extensions/ObjectExtensions.cs index e19bce3..4496d83 100644 --- a/N.EntityFrameworkCore.Extensions/Extensions/ObjectExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Extensions/ObjectExtensions.cs @@ -31,4 +31,4 @@ public static object GetPrivateFieldValue(this object obj, string propName) return propertyInfo.GetValue(obj, null); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Extensions/SqlStatementExtensions.cs b/N.EntityFrameworkCore.Extensions/Extensions/SqlStatementExtensions.cs index 0573f72..9d8460a 100644 --- a/N.EntityFrameworkCore.Extensions/Extensions/SqlStatementExtensions.cs +++ b/N.EntityFrameworkCore.Extensions/Extensions/SqlStatementExtensions.cs @@ -1,9 +1,9 @@ -using N.EntityFrameworkCore.Extensions.Sql; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using N.EntityFrameworkCore.Extensions.Sql; namespace N.EntityFrameworkCore.Extensions.Extensions { @@ -15,4 +15,4 @@ internal static void WriteInsert(this SqlStatement statement, IEnumerable= 10 ? 10 : sqlText.Length - i; string keyword = StartsWithString(sqlText.Substring(i, maxLenToSearch), keywords, StringComparison.OrdinalIgnoreCase); - bool isWordStart = i > 0 ? sqlText[i - 1] == ' ' || (i > 1 && sqlText.Substring(i-2,2) == "\r\n") : true; + bool isWordStart = i > 0 ? sqlText[i - 1] == ' ' || (i > 1 && sqlText.Substring(i - 2, 2) == "\r\n") : true; //Process Sql clause if (keyword != null && curClause != keyword && isWordStart) { @@ -43,11 +43,11 @@ private void Initialize(string sqlText) { var declareParts = inputText.Substring(0, inputText.IndexOf(";")).Trim().Split(" "); int sizeStartIndex = declareParts[1].IndexOf("("); - int sizeLength = declareParts[1].IndexOf(")") - (sizeStartIndex+1); + int sizeLength = declareParts[1].IndexOf(")") - (sizeStartIndex + 1); string dbTypeString = sizeStartIndex != -1 ? declareParts[1].Substring(0, sizeStartIndex) : declareParts[1]; SqlDbType dbType = (SqlDbType)Enum.Parse(typeof(SqlDbType), dbTypeString, true); - int size = sizeStartIndex != -1 ? - Convert.ToInt32(declareParts[1].Substring(sizeStartIndex+1, sizeLength)) : 0; + int size = sizeStartIndex != -1 ? + Convert.ToInt32(declareParts[1].Substring(sizeStartIndex + 1, sizeLength)) : 0; string value = GetDeclareValue(declareParts[3]); Parameters.Add(new SqlParameter(declareParts[0], dbType, size) { Value = value }); } @@ -71,7 +71,7 @@ private void Initialize(string sqlText) private string GetDeclareValue(string value) { - if(value.StartsWith("'")) + if (value.StartsWith("'")) { return value.Substring(1, value.Length - 2); } @@ -95,7 +95,7 @@ public override string ToString() } private static string StartsWithString(string textToSearch, IEnumerable valuesToFind, StringComparison stringComparison) { - string value=null; + string value = null; foreach (var valueToFind in valuesToFind) { if (textToSearch.StartsWith(valueToFind, stringComparison)) @@ -115,14 +115,14 @@ public String GetTableAlias() { var sqlFromClause = Clauses.First(o => o.Name == "FROM"); var startIndex = sqlFromClause.InputText.LastIndexOf(" AS "); - return startIndex > 0 ? sqlFromClause.InputText.Substring(startIndex+4) : ""; + return startIndex > 0 ? sqlFromClause.InputText.Substring(startIndex + 4) : ""; } public void ChangeToDelete() { Validate(); var sqlClause = Clauses.FirstOrDefault(); var sqlFromClause = Clauses.First(o => o.Name == "FROM"); - if(sqlClause != null) + if (sqlClause != null) { sqlClause.Name = "DELETE"; int aliasStartIndex = sqlFromClause.InputText.IndexOf("AS ") + 3; @@ -149,7 +149,7 @@ internal void ChangeToInsert(string tableName, Expression> in string insertValueExpression = string.Format("INTO {0} ({1})", tableName, columnsToInsert); Clauses.Insert(0, new SqlClause { Name = "INSERT", InputText = insertValueExpression }); sqlSelectClause.InputText = columnsToInsert; - + } internal void SelectColumns(IEnumerable columns) { @@ -162,7 +162,7 @@ internal void SelectColumns(IEnumerable columns) } private void Validate() { - if(Clauses.Count == 0) + if (Clauses.Count == 0) { throw new Exception("You must parse a valid sql statement before you can use this function."); } diff --git a/N.EntityFrameworkCore.Extensions/Sql/SqlExpression.cs b/N.EntityFrameworkCore.Extensions/Sql/SqlExpression.cs index 12dc425..9ad34b1 100644 --- a/N.EntityFrameworkCore.Extensions/Sql/SqlExpression.cs +++ b/N.EntityFrameworkCore.Extensions/Sql/SqlExpression.cs @@ -1,13 +1,13 @@ -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using N.EntityFrameworkCore.Extensions.Util; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Runtime.InteropServices.ObjectiveC; using System.Text; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using N.EntityFrameworkCore.Extensions.Util; namespace N.EntityFrameworkCore.Extensions.Sql { @@ -83,4 +83,4 @@ private string ToSql() return sbSql.ToString(); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Sql/SqlKeyword.cs b/N.EntityFrameworkCore.Extensions/Sql/SqlKeyword.cs index bf461bb..9418968 100644 --- a/N.EntityFrameworkCore.Extensions/Sql/SqlKeyword.cs +++ b/N.EntityFrameworkCore.Extensions/Sql/SqlKeyword.cs @@ -33,4 +33,4 @@ public enum SqlKeyword Identity_Insert, Semicolon, } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Sql/SqlPart.cs b/N.EntityFrameworkCore.Extensions/Sql/SqlPart.cs index 6a7a3c0..0c1669e 100644 --- a/N.EntityFrameworkCore.Extensions/Sql/SqlPart.cs +++ b/N.EntityFrameworkCore.Extensions/Sql/SqlPart.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.Identity.Client; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using Microsoft.Identity.Client; namespace N.EntityFrameworkCore.Extensions.Sql { @@ -29,4 +29,4 @@ private bool GetIgnoreOutput() } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Sql/SqlStatement.cs b/N.EntityFrameworkCore.Extensions/Sql/SqlStatement.cs index 53d8910..5a22915 100644 --- a/N.EntityFrameworkCore.Extensions/Sql/SqlStatement.cs +++ b/N.EntityFrameworkCore.Extensions/Sql/SqlStatement.cs @@ -1,13 +1,13 @@ -using Microsoft.Extensions.Options; -using N.EntityFrameworkCore.Extensions.Extensions; -using N.EntityFrameworkCore.Extensions.Util; -using System; +using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using N.EntityFrameworkCore.Extensions.Extensions; +using N.EntityFrameworkCore.Extensions.Util; namespace N.EntityFrameworkCore.Extensions.Sql { @@ -50,9 +50,9 @@ internal void SetIdentityInsert(string tableName, bool enable) //{ //} - internal static SqlStatement CreateMerge(string sourceTableName, string targetTableName, string joinOnCondition, - IEnumerable insertColumns, IEnumerable updateColumns, IEnumerable outputColumns, - bool deleteIfNotMatched=false, bool hasIdentityColumn=false) + internal static SqlStatement CreateMerge(string sourceTableName, string targetTableName, string joinOnCondition, + IEnumerable insertColumns, IEnumerable updateColumns, IEnumerable outputColumns, + bool deleteIfNotMatched = false, bool hasIdentityColumn = false) { var statement = new SqlStatement(); if (hasIdentityColumn) @@ -65,7 +65,7 @@ internal static SqlStatement CreateMerge(string sourceTableName, string targetTa statement.CreatePart(SqlKeyword.Matched); statement.CreatePart(SqlKeyword.Then); statement.WriteInsert(insertColumns); - if(updateColumns.Any()) + if (updateColumns.Any()) { var updateSetColumns = updateColumns.Select(c => $"t.[{c}]=s.[{c}]"); statement.CreatePart(SqlKeyword.When); @@ -74,7 +74,7 @@ internal static SqlStatement CreateMerge(string sourceTableName, string targetTa statement.CreatePart(SqlKeyword.Update); statement.CreatePart(SqlKeyword.Set, SqlExpression.Set(updateSetColumns)); } - if(deleteIfNotMatched) + if (deleteIfNotMatched) { statement.CreatePart(SqlKeyword.When); statement.CreatePart(SqlKeyword.Not); @@ -84,7 +84,7 @@ internal static SqlStatement CreateMerge(string sourceTableName, string targetTa statement.CreatePart(SqlKeyword.Then); statement.CreatePart(SqlKeyword.Delete); } - if(outputColumns.Any()) + if (outputColumns.Any()) statement.CreatePart(SqlKeyword.Output, SqlExpression.Columns(outputColumns)); statement.CreatePart(SqlKeyword.Semicolon); @@ -96,7 +96,7 @@ internal static SqlStatement CreateMerge(string sourceTableName, string targetTa private string ToSql() { StringBuilder sbSql = new StringBuilder(); - foreach(var part in SqlParts) + foreach (var part in SqlParts) { if (part.Keyword == SqlKeyword.Semicolon) { @@ -133,4 +133,4 @@ private string ToSql() return sbSql.ToString(); } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Util/CommonUtil.cs b/N.EntityFrameworkCore.Extensions/Util/CommonUtil.cs index 926a323..0e2f55a 100644 --- a/N.EntityFrameworkCore.Extensions/Util/CommonUtil.cs +++ b/N.EntityFrameworkCore.Extensions/Util/CommonUtil.cs @@ -1,10 +1,10 @@ -using Microsoft.Data.SqlClient; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; +using Microsoft.Data.SqlClient; namespace N.EntityFrameworkCore.Extensions.Util { @@ -106,4 +106,4 @@ internal static string GetJoinConditionSql(Expression> joinKeyE return joinConditionSql; } } -} +} \ No newline at end of file diff --git a/N.EntityFrameworkCore.Extensions/Util/SqlUtil.cs b/N.EntityFrameworkCore.Extensions/Util/SqlUtil.cs index 5d9c974..4863d7a 100644 --- a/N.EntityFrameworkCore.Extensions/Util/SqlUtil.cs +++ b/N.EntityFrameworkCore.Extensions/Util/SqlUtil.cs @@ -1,10 +1,10 @@ -using Microsoft.Data.SqlClient; -using N.EntityFrameworkCore.Extensions.Util; -using System; +using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; +using Microsoft.Data.SqlClient; +using N.EntityFrameworkCore.Extensions.Util; namespace N.EntityFrameworkCore.Extensions {