From 1cdef14d5cd1c5bfad49963e839bd8fe80a40bd9 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Sun, 17 Jan 2021 09:10:30 -0800 Subject: [PATCH] Samples code cleanup and verification that all samples run Fixes #2935 --- samples/core/.editorconfig | 257 ++++++++++++++++++ samples/core/Benchmarks/AverageBlogRanking.cs | 17 +- samples/core/Benchmarks/Benchmarks.csproj | 4 +- .../DynamicallyConstructedQueries.cs | 3 - samples/core/Benchmarks/Inheritance.cs | 7 +- .../core/Benchmarks/QueryTrackingBehavior.cs | 13 +- .../core/CascadeDeletes/CascadeDeletes.csproj | 6 +- .../OptionalDependentsSamples.cs | 18 +- samples/core/CascadeDeletes/Program.cs | 5 +- .../RequiredDependentsSamples.cs | 18 +- .../WithDatabaseCycleSamples.cs | 5 +- .../AccessingTrackedEntities.csproj | 4 +- .../AccessingTrackedEntities/Samples.cs | 6 +- .../AdditionalChangeTrackingFeatures.csproj | 4 +- .../Samples.cs | 38 +-- .../ChangeDetectionAndNotifications.csproj | 6 +- .../ChangeTrackingProxiesSamples.cs | 77 +++--- .../NotificationEntitiesSamples.cs | 6 +- .../NotificationWithBaseSamples.cs | 6 +- .../SnapshotSamples.cs | 6 +- .../ChangeTrackerDebugging.csproj | 4 +- .../ChangeTrackerDebugging/Samples.cs | 21 +- .../ChangeTrackingInEFCore.csproj | 4 +- .../ExplicitKeysSamples.cs | 23 +- .../GeneratedKeysSamples.cs | 39 ++- .../ChangingFKsAndNavigations.csproj | 4 +- .../ExplicitJoinEntityAndSkipsSamples.cs | 18 +- .../ExplicitJoinEntitySamples.cs | 18 +- .../ExplicitJoinEntityWithPayloadSamples.cs | 18 +- ...licitJoinEntityWithStringPayloadSamples.cs | 25 +- .../OptionalRelationshipsSamples.cs | 18 +- .../RequiredRelationshipsSamples.cs | 18 +- .../IdentityResolutionInEFCore.csproj | 4 +- .../IdentityResolutionSamples.cs | 49 +--- .../SerializedGraphExamples.cs | 68 ++--- .../CompiledQueries/CompiledQueries.csproj | 2 +- .../Model/AdventureWorksContext.cs | 42 ++- .../core/CompiledQueries/Model/Customer.cs | 5 +- samples/core/CompiledQueries/Program.cs | 50 ++-- samples/core/Cosmos/Cosmos.csproj | 2 +- .../Cosmos/ModelBuilding/OptionsContext.cs | 36 +-- .../core/Cosmos/ModelBuilding/OrderContext.cs | 6 +- samples/core/Cosmos/ModelBuilding/Sample.cs | 38 +-- samples/core/Cosmos/Program.cs | 5 +- .../core/Cosmos/UnstructuredData/Sample.cs | 12 +- .../DbContextPooling/DbContextPooling.csproj | 2 +- samples/core/GetStarted/EFGetStarted.csproj | 4 +- .../20190917222642_InitialCreate.cs | 5 +- .../BloggingContextModelSnapshot.cs | 16 +- samples/core/GetStarted/Program.cs | 12 +- samples/core/Intro/Intro.csproj | 4 +- .../20191019191556_InitialCreate.cs | 5 +- .../BloggingContextModelSnapshot.cs | 16 +- samples/core/Intro/Model.cs | 4 +- samples/core/Intro/Program.cs | 15 +- .../KeylessEntityTypes.csproj | 4 +- samples/core/KeylessEntityTypes/Program.cs | 24 +- samples/core/Miscellaneous/Async/Async.csproj | 5 +- samples/core/Miscellaneous/Async/Program.cs | 4 +- .../AsyncWithSystemInteractive.csproj | 5 +- .../AsyncWithSystemInteractive/Program.cs | 4 +- .../CachingInterception.csproj | 2 +- .../Collations/Collations.csproj | 3 +- .../core/Miscellaneous/Collations/Program.cs | 3 +- .../CommandInterception/BlogsContext.cs | 9 +- .../CommandInterception.csproj | 2 +- .../TaggedQueryCommandInterceptor.cs | 2 +- .../CommandLine/ApplicationService.cs | 5 + .../CommandLine/CommandLine.csproj | 4 +- .../Miscellaneous/CommandLine/CustomTools.cs | 2 +- .../CommandLine/DesignTimeServices.cs | 4 +- .../ApplicationDbContext.cs | 5 +- .../InheritDbContext/ApplicationDbContext.cs | 1 - .../FactoryServicesExample.cs | 5 +- .../WithContextFactory/MyController.cs | 1 - .../ConnectionInterception.csproj | 2 +- .../ConnectionResiliency.csproj | 5 +- .../ConnectionResiliency/Program.cs | 66 +++-- .../DiagnosticListeners.csproj | 2 +- .../DiagnosticListeners/Program.cs | 10 +- .../core/Miscellaneous/Events/Events.csproj | 2 +- samples/core/Miscellaneous/Events/Program.cs | 8 +- .../Logging/Logging/BloggingContext.cs | 11 +- .../Logging/BloggingContextWithFiltering.cs | 10 +- .../Logging/Logging/Logging.csproj | 4 +- .../Logging/SimpleLogging/Program.cs | 7 +- .../SimpleLogging/SimpleLogging.csproj | 4 +- .../NullableReferenceTypes/Customer.cs | 6 +- .../CustomerWithWarning.cs | 1 + .../CustomerWithoutNullableReferenceTypes.cs | 9 +- .../NullableReferenceTypes.csproj | 4 +- .../NullableReferenceTypesContext.cs | 3 +- .../NullableReferenceTypes/Program.cs | 21 +- .../SaveChangesInterception/AuditContext.cs | 2 +- .../AuditingInterceptor.cs | 22 +- .../SaveChangesInterception/Program.cs | 10 +- .../SaveChangesInterception.csproj | 2 +- .../Testing/BusinessLogic/BlogService.cs | 2 +- .../Testing/BusinessLogic/BloggingContext.cs | 15 +- .../BusinessLogic/BusinessLogic.csproj | 2 +- .../Testing/ItemsWebApi/ItemsWebApi/Item.cs | 3 +- .../ItemsWebApi/ItemsWebApi/ItemsContext.cs | 24 +- .../ItemsWebApi/ItemsWebApi.csproj | 2 +- .../ItemsWebApi/ItemsWebApi/Program.cs | 2 +- .../ItemsWebApi/ItemsWebApi/Startup.cs | 7 +- .../Testing/ItemsWebApi/ItemsWebApi/Tag.cs | 2 +- .../SharedDatabaseTests/SharedDatabaseTest.cs | 1 - .../SharedDatabaseTests.csproj | 2 +- .../Tests/InMemoryItemsControllerTest.cs | 2 +- .../Tests/SqlServerItemsControllerTest.cs | 2 +- .../SqliteInMemoryItemsControllerTest.cs | 2 +- .../Tests/SqliteItemsControllerTest.cs | 2 +- .../Testing/ItemsWebApi/Tests/Tests.csproj | 6 +- .../TestProject/InMemory/BlogServiceTests.cs | 15 +- .../TestProject/SQLite/BlogServiceTests.cs | 4 +- .../Testing/TestProject/TestProject.csproj | 4 +- .../core/Modeling/Conventions/AlternateKey.cs | 6 +- .../core/Modeling/Conventions/BackingField.cs | 11 +- .../Modeling/Conventions/Conventions.csproj | 4 +- .../core/Modeling/Conventions/EntityTypes.cs | 9 +- .../Modeling/Conventions/InheritanceDbSets.cs | 3 +- samples/core/Modeling/Conventions/KeyId.cs | 7 +- samples/core/Modeling/Conventions/Program.cs | 8 +- .../Conventions/Relationships/Full.cs | 4 +- .../Conventions/Relationships/NoForeignKey.cs | 6 +- .../Relationships/OneNavigation.cs | 6 +- .../Conventions/Relationships/OneToOne.cs | 3 +- .../Modeling/Conventions/ShadowForeignKey.cs | 6 +- .../Modeling/DataAnnotations/BackingField.cs | 4 +- .../Modeling/DataAnnotations/ColumnComment.cs | 4 +- .../DataAnnotations/ColumnDataType.cs | 6 +- .../Modeling/DataAnnotations/ColumnName.cs | 7 +- .../Modeling/DataAnnotations/Concurrency.cs | 6 +- .../DataAnnotations/DataAnnotations.csproj | 2 +- .../DataAnnotations/IgnoreProperty.cs | 6 +- .../Modeling/DataAnnotations/IgnoreType.cs | 6 +- .../core/Modeling/DataAnnotations/Index.cs | 2 +- .../DataAnnotations/IndexComposite.cs | 2 +- .../Modeling/DataAnnotations/IndexName.cs | 2 +- .../Modeling/DataAnnotations/IndexUnique.cs | 2 +- .../Modeling/DataAnnotations/KeySingle.cs | 8 +- .../core/Modeling/DataAnnotations/Keyless.cs | 4 +- .../Modeling/DataAnnotations/MaxLength.cs | 7 +- .../core/Modeling/DataAnnotations/Program.cs | 12 +- .../Relationships/ForeignKey.cs | 6 +- .../Relationships/InverseProperty.cs | 6 +- .../core/Modeling/DataAnnotations/Required.cs | 7 +- .../Modeling/DataAnnotations/TableComment.cs | 3 +- .../Modeling/DataAnnotations/TableName.cs | 6 +- .../DataAnnotations/TableNameAndSchema.cs | 6 +- .../Modeling/DataAnnotations/Timestamp.cs | 6 +- .../DataAnnotations/ValueGeneratedNever.cs | 7 +- .../DataAnnotations/ValueGeneratedOnAdd.cs | 7 +- .../ValueGeneratedOnAddOrUpdate.cs | 7 +- .../Modeling/DataSeeding/DataSeeding.csproj | 4 +- .../DataSeeding/DataSeedingContext.cs | 22 +- .../Migrations/20181102235626_Initial.cs | 5 +- .../DataSeedingContextModelSnapshot.cs | 20 +- samples/core/Modeling/DataSeeding/Program.cs | 5 +- .../Modeling/DynamicModel/DynamicModel.csproj | 2 +- samples/core/Modeling/DynamicModel/Program.cs | 2 +- .../FluentAPI/AlternateKeyComposite.cs | 4 +- .../Modeling/FluentAPI/AlternateKeyName.cs | 4 +- .../Modeling/FluentAPI/AlternateKeySingle.cs | 4 +- .../core/Modeling/FluentAPI/BackingField.cs | 15 +- .../FluentAPI/BackingFieldAccessMode.cs | 16 +- .../FluentAPI/BackingFieldNoProperty.cs | 6 +- .../core/Modeling/FluentAPI/ColumnComment.cs | 3 +- .../core/Modeling/FluentAPI/ColumnDataType.cs | 13 +- samples/core/Modeling/FluentAPI/ColumnName.cs | 2 +- .../core/Modeling/FluentAPI/ComputedColumn.cs | 2 +- .../core/Modeling/FluentAPI/Concurrency.cs | 2 +- .../core/Modeling/FluentAPI/DefaultSchema.cs | 2 +- .../core/Modeling/FluentAPI/DefaultValue.cs | 2 +- .../Modeling/FluentAPI/DefaultValueSql.cs | 6 +- .../FluentAPI/EntityTypeConfiguration.cs | 2 +- .../core/Modeling/FluentAPI/FluentAPI.csproj | 2 +- .../core/Modeling/FluentAPI/IgnoreProperty.cs | 6 +- samples/core/Modeling/FluentAPI/IgnoreType.cs | 6 +- samples/core/Modeling/FluentAPI/Index.cs | 2 +- .../core/Modeling/FluentAPI/IndexComposite.cs | 2 +- .../core/Modeling/FluentAPI/IndexFilter.cs | 2 +- .../core/Modeling/FluentAPI/IndexInclude.cs | 9 +- samples/core/Modeling/FluentAPI/IndexName.cs | 2 +- .../core/Modeling/FluentAPI/IndexNoFilter.cs | 2 +- .../core/Modeling/FluentAPI/IndexUnique.cs | 2 +- .../Modeling/FluentAPI/IndexerProperty.cs | 10 +- .../core/Modeling/FluentAPI/KeyComposite.cs | 4 +- samples/core/Modeling/FluentAPI/KeyName.cs | 2 +- samples/core/Modeling/FluentAPI/KeySingle.cs | 4 +- samples/core/Modeling/FluentAPI/Keyless.cs | 2 +- samples/core/Modeling/FluentAPI/MaxLength.cs | 2 +- .../Modeling/FluentAPI/PrecisionAndScale.cs | 6 +- samples/core/Modeling/FluentAPI/Program.cs | 8 +- .../FluentAPI/Relationships/CascadeDelete.cs | 7 +- .../Relationships/CompositeForeignKey.cs | 6 +- .../Relationships/CompositePrincipalKey.cs | 6 +- .../FluentAPI/Relationships/ConstraintName.cs | 6 +- .../FluentAPI/Relationships/ForeignKey.cs | 6 +- .../Modeling/FluentAPI/Relationships/Full.cs | 6 +- .../FluentAPI/Relationships/ManyToMany.cs | 4 +- .../Relationships/ManyToManyPayload.cs | 6 +- .../Relationships/ManyToManyShared.cs | 6 +- .../Relationships/NavigationConfiguration.cs | 8 +- .../FluentAPI/Relationships/NoForeignKey.cs | 6 +- .../FluentAPI/Relationships/NoNavigation.cs | 3 +- .../FluentAPI/Relationships/OneNavigation.cs | 6 +- .../FluentAPI/Relationships/OneToOne.cs | 3 +- .../FluentAPI/Relationships/PrincipalKey.cs | 6 +- .../FluentAPI/Relationships/Required.cs | 6 +- .../Relationships/ShadowForeignKey.cs | 6 +- samples/core/Modeling/FluentAPI/Required.cs | 2 +- samples/core/Modeling/FluentAPI/Sequence.cs | 2 +- .../FluentAPI/SequenceConfiguration.cs | 2 +- .../core/Modeling/FluentAPI/ShadowProperty.cs | 6 +- samples/core/Modeling/FluentAPI/SharedType.cs | 19 +- .../Modeling/FluentAPI/TPTConfiguration.cs | 4 +- .../core/Modeling/FluentAPI/TableComment.cs | 3 +- .../FluentAPI/TableExcludeFromMigrations.cs | 2 +- samples/core/Modeling/FluentAPI/TableName.cs | 2 +- .../Modeling/FluentAPI/TableNameAndSchema.cs | 2 +- samples/core/Modeling/FluentAPI/Timestamp.cs | 2 +- .../Modeling/FluentAPI/ValueGeneratedNever.cs | 2 +- .../Modeling/FluentAPI/ValueGeneratedOnAdd.cs | 6 +- .../FluentAPI/ValueGeneratedOnAddOrUpdate.cs | 6 +- ...edOnAddOrUpdateWithPropertySaveBehavior.cs | 6 +- .../Modeling/FluentAPI/ViewNameAndSchema.cs | 2 +- .../OwnedEntities/OwnedEntities.csproj | 4 +- .../OwnedEntities/OwnedEntityContext.cs | 58 ++-- .../core/Modeling/OwnedEntities/Program.cs | 19 +- .../core/Modeling/TableSplitting/Program.cs | 19 +- .../TableSplitting/TableSplitting.csproj | 4 +- .../TableSplitting/TableSplittingContext.cs | 27 +- .../MappingImmutableClassProperty.cs | 1 - .../OverridingByteArrayComparisons.cs | 9 +- .../core/Modeling/ValueConversions/Program.cs | 3 +- .../ValueConversions/ValueConversions.csproj | 2 +- .../core/Performance/BatchTweakingContext.cs | 3 - samples/core/Performance/BloggingContext.cs | 3 - samples/core/Performance/EmployeeContext.cs | 3 - .../Performance/ExtensionsLoggingContext.cs | 3 - .../LazyLoading/LazyBloggingContext.cs | 3 - samples/core/Performance/Performance.csproj | 4 +- samples/core/Performance/Program.cs | 39 ++- .../ClientEvaluation/BloggingContext.cs | 3 +- .../ClientEvaluation/ClientEvaluation.csproj | 4 +- .../core/Querying/ClientEvaluation/Program.cs | 17 +- .../Querying/ComplexQuery/BloggingContext.cs | 48 +++- .../Querying/ComplexQuery/ComplexQuery.csproj | 4 +- samples/core/Querying/ComplexQuery/Program.cs | 27 +- .../NullSemantics/NullSemantics.csproj | 2 +- .../NullSemantics/NullSemanticsContext.cs | 50 +++- .../core/Querying/NullSemantics/Program.cs | 16 +- .../core/Querying/Overview/BloggingContext.cs | 3 +- .../core/Querying/Overview/Overview.csproj | 4 +- samples/core/Querying/Overview/Program.cs | 10 +- .../Querying/QueryFilters/AnimalContext.cs | 1 - .../Querying/QueryFilters/BloggingContext.cs | 4 +- samples/core/Querying/QueryFilters/Program.cs | 19 +- .../Querying/QueryFilters/QueryFilters.csproj | 4 +- .../core/Querying/RawSQL/BloggingContext.cs | 39 ++- samples/core/Querying/RawSQL/Program.cs | 20 +- samples/core/Querying/RawSQL/RawSQL.csproj | 4 +- .../Querying/RelatedData/BloggingContext.cs | 48 +++- samples/core/Querying/RelatedData/Program.cs | 66 +++-- .../Querying/RelatedData/RelatedData.csproj | 4 +- samples/core/Querying/Tags/Program.cs | 20 +- samples/core/Querying/Tags/SpatialContext.cs | 20 +- samples/core/Querying/Tags/Tags.csproj | 2 +- .../core/Querying/Tracking/BloggingContext.cs | 3 +- samples/core/Querying/Tracking/Program.cs | 46 +--- .../core/Querying/Tracking/Tracking.csproj | 4 +- .../UserDefinedFunctionMapping/Model.cs | 123 ++++++--- .../UserDefinedFunctionMapping/Program.cs | 13 +- .../UserDefinedFunctionMapping.csproj | 4 +- samples/core/Samples.sln.DotSettings | 4 +- samples/core/Saving/Basics/BloggingContext.cs | 3 +- samples/core/Saving/Basics/Sample.cs | 2 +- .../Saving/CascadeDelete/BloggingContext.cs | 10 +- samples/core/Saving/CascadeDelete/Sample.cs | 29 +- .../Saving/Disconnected/BloggingContext.cs | 3 +- .../core/Saving/Disconnected/EntityBase.cs | 2 +- samples/core/Saving/Disconnected/Sample.cs | 15 +- samples/core/Saving/Program.cs | 19 +- samples/core/Saving/RelatedData/Sample.cs | 7 +- samples/core/Saving/Saving.csproj | 2 +- .../Saving/Transactions/AmbientTransaction.cs | 12 +- .../Transactions/CommitableTransaction.cs | 12 +- .../Transactions/ControllingTransaction.cs | 5 +- .../Transactions/ExternalDbTransaction.cs | 12 +- .../Saving/Transactions/ManagingSavepoints.cs | 5 +- .../Saving/Transactions/SharingTransaction.cs | 8 +- .../Schemas/Migrations/CustomOperation.cs | 22 +- .../Migrations/CustomOperationMultiSql.cs | 4 +- .../Schemas/Migrations/CustomOperationSql.cs | 6 +- .../Migrations/MigrationTableNameContext.cs | 2 +- .../core/Schemas/Migrations/Migrations.csproj | 2 +- .../Schemas/Migrations/MyHistoryRepository.cs | 4 +- .../ApplicationDbContext.cs | 5 +- .../WebApplication1.Data.csproj | 4 +- .../00000000000000_CreateIdentitySchema.cs | 16 +- .../ApplicationDbContextModelSnapshot.cs | 40 ++- .../Areas/Identity/Pages/_ViewStart.cshtml | 2 +- .../WebApplication1/Pages/Error.cshtml | 2 +- .../WebApplication1/Pages/Error.cshtml.cs | 4 - .../WebApplication1/Pages/Index.cshtml | 2 +- .../WebApplication1/Pages/Index.cshtml.cs | 8 +- .../WebApplication1/Pages/Privacy.cshtml | 2 +- .../WebApplication1/Pages/Privacy.cshtml.cs | 7 +- .../Pages/Shared/_Layout.cshtml | 78 +++--- .../Pages/Shared/_LoginPartial.cshtml | 45 ++- .../Shared/_ValidationScriptsPartial.cshtml | 2 +- .../WebApplication1/Pages/_ViewImports.cshtml | 2 +- .../WebApplication1/Pages/_ViewStart.cshtml | 2 +- .../WebApplication1/Program.cs | 11 +- .../WebApplication1/Startup.cs | 17 +- .../WebApplication1/WebApplication1.csproj | 6 +- .../20200915225801_InitialCreate.cs | 10 +- .../BlogContextModelSnapshot.cs | 32 +-- .../20200915230052_InitialCreate.cs | 10 +- .../BlogContextModelSnapshot.cs | 31 +-- .../WorkerService1/Program.cs | 4 +- .../WorkerService1/Worker.cs | 8 +- .../WorkerService1/WorkerService1.csproj | 6 +- .../Spatial/Projections/GeometryExtensions.cs | 11 +- samples/core/Spatial/Projections/Program.cs | 1 - samples/core/Spatial/SqlServer/Models/City.cs | 2 +- .../core/Spatial/SqlServer/Models/Country.cs | 2 +- .../Spatial/SqlServer/Models/StateProvince.cs | 2 +- .../Models/WideWorldImportersContext.cs | 4 +- samples/core/Spatial/SqlServer/Program.cs | 37 ++- .../core/Spatial/SqlServer/SqlServer.csproj | 4 +- .../AzureDatabase/AzureSqlContext.cs | 3 +- samples/core/SqlServer/Program.cs | 2 +- samples/core/SqlServer/SqlServer.csproj | 2 +- .../core/SqlServer/ValueGeneration/Blog.cs | 4 +- .../ValueGeneration/ExplicitIdentityValues.cs | 3 - .../ValueGeneration/IdentityOptionsContext.cs | 3 - 338 files changed, 1885 insertions(+), 1694 deletions(-) create mode 100644 samples/core/.editorconfig diff --git a/samples/core/.editorconfig b/samples/core/.editorconfig new file mode 100644 index 0000000000..a241d5f867 --- /dev/null +++ b/samples/core/.editorconfig @@ -0,0 +1,257 @@ +# Schema: http://EditorConfig.org +# Docs: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference + +# top-most EditorConfig file +root = true + +# Don't use tabs for indentation. +[*] +indent_style = space +trim_trailing_whitespace = true +guidelines = 140 +max_line_length = 140 + +# Code files +[*.{cs,csx,vb,vbx}] +indent_size = 4 +insert_final_newline = true +#charset = utf-8-bom + +# Xml project files +[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] +indent_size = 2 + +# Xml config files +[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct,xml,stylecop}] +indent_size = 2 + +# JSON files +[*.json] +indent_size = 2 + +# Powershell files +[*.ps1] +indent_size = 2 + +# Shell scripts +[*.sh] +end_of_line = lf +indent_size = 2 + +[*.{cmd,bat}] +end_of_line = crlf +indent_size = 2 + +## Language conventions +# Dotnet code style settings: +[*.{cs,vb}] +# "This." and "Me." qualifiers +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# Language keywords instead of framework type names for type references +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = always:suggestion +dotnet_style_readonly_field = true:warning + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion + +# Null-checking preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion + +# CSharp code style settings: +[*.cs] +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,const,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +# Implicit and explicit types +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion + +# Expression-bodied members +# Explicitly disabled due to difference in coding style between source and tests +#csharp_style_expression_bodied_methods = false:silent +#csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:suggestion +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_accessors = true:suggestion + +# Pattern matching +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion + +# Inlined variable declarations +csharp_style_inlined_variable_declaration = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion + +# Null-checking preference +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Code block preferences +csharp_prefer_braces = true:suggestion + +## Formatting conventions +# Dotnet formatting settings: +[*.{cs,vb}] +# Organize usings +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = false + +# CSharp formatting settings: +[*.cs] +# Newline options +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Identation options +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents_when_block = false +csharp_indent_switch_labels = true +csharp_indent_case_contents = true +csharp_indent_labels = no_change + +# Spacing options +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_declaration_statements = do_not_ignore +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_declaration_name_and_open_parenthesis = false +csharp_space_between_square_brackets = false + +# Wrap options +csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true + +## Naming conventions +[*.{cs,vb}] + +## Naming styles + +dotnet_naming_style.pascal_case_style.capitalization = pascal_case +dotnet_naming_style.camel_case_style.capitalization = camel_case + +# PascalCase with I prefix +dotnet_naming_style.interface_style.capitalization = pascal_case +dotnet_naming_style.interface_style.required_prefix = I + +# PascalCase with T prefix +dotnet_naming_style.type_parameter_style.capitalization = pascal_case +dotnet_naming_style.type_parameter_style.required_prefix = T + +# camelCase with _ prefix +dotnet_naming_style._camelCase.capitalization = camel_case +dotnet_naming_style._camelCase.required_prefix = _ + +## Rules +# Interfaces +dotnet_naming_symbols.interface_symbol.applicable_kinds = interface +dotnet_naming_symbols.interface_symbol.applicable_accessibilities = * +dotnet_naming_rule.interface_naming.symbols = interface_symbol +dotnet_naming_rule.interface_naming.style = interface_style +dotnet_naming_rule.interface_naming.severity = suggestion + +# Classes, Structs, Enums, Properties, Methods, Local Functions, Events, Namespaces +dotnet_naming_symbols.class_symbol.applicable_kinds = class, struct, enum, property, method, local_function, event, namespace, delegate +dotnet_naming_symbols.class_symbol.applicable_accessibilities = * + +dotnet_naming_rule.class_naming.symbols = class_symbol +dotnet_naming_rule.class_naming.style = pascal_case_style +dotnet_naming_rule.class_naming.severity = suggestion + +# Type Parameters +dotnet_naming_symbols.type_parameter_symbol.applicable_kinds = type_parameter +dotnet_naming_symbols.type_parameter_symbol.applicable_accessibilities = * + +dotnet_naming_rule.type_parameter_naming.symbols = type_parameter_symbol +dotnet_naming_rule.type_parameter_naming.style = type_parameter_style +dotnet_naming_rule.type_parameter_naming.severity = suggestion + +# Visible Fields +dotnet_naming_symbols.public_field_symbol.applicable_kinds = field +dotnet_naming_symbols.public_field_symbol.applicable_accessibilities = public, internal, protected, protected_internal, private_protected + +dotnet_naming_rule.public_field_naming.symbols = public_field_symbol +dotnet_naming_rule.public_field_naming.style = pascal_case_style +dotnet_naming_rule.public_field_naming.severity = suggestion + +# Private constant Fields +dotnet_naming_symbols.const_field_symbol.applicable_kinds = field +dotnet_naming_symbols.const_field_symbol.applicable_accessibilities = private +dotnet_naming_symbols.const_field_symbol.required_modifiers = const + +dotnet_naming_rule.const_field_naming.symbols = const_field_symbol +dotnet_naming_rule.const_field_naming.style = pascal_case_style +dotnet_naming_rule.const_field_naming.severity = suggestion + +# Private Fields +dotnet_naming_symbols.private_field_symbol.applicable_kinds = field +dotnet_naming_symbols.private_field_symbol.applicable_accessibilities = private + +dotnet_naming_rule.private_field_naming.symbols = private_field_symbol +dotnet_naming_rule.private_field_naming.style = _camelCase +dotnet_naming_rule.private_field_naming.severity = suggestion + +# Parameters +dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter +dotnet_naming_symbols.parameter_symbol.applicable_accessibilities = * + +dotnet_naming_rule.parameter_naming.symbols = parameter_symbol +dotnet_naming_rule.parameter_naming.style = camel_case_style +dotnet_naming_rule.parameter_naming.severity = suggestion + +# Everything Local +dotnet_naming_symbols.everything_else.applicable_kinds = local +dotnet_naming_symbols.everything_else.applicable_accessibilities = * + +dotnet_naming_rule.everything_else_naming.symbols = everything_else +dotnet_naming_rule.everything_else_naming.style = camel_case_style +dotnet_naming_rule.everything_else_naming.severity = suggestion diff --git a/samples/core/Benchmarks/AverageBlogRanking.cs b/samples/core/Benchmarks/AverageBlogRanking.cs index 33d762b811..41cc3cbee1 100644 --- a/samples/core/Benchmarks/AverageBlogRanking.cs +++ b/samples/core/Benchmarks/AverageBlogRanking.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Linq; using BenchmarkDotNet.Attributes; @@ -12,7 +9,7 @@ namespace Benchmarks public class AverageBlogRanking { [Params(1000)] - public int NumBlogs; // number of records to write [once], and read [each pass] + public int NumBlogs; // number of records to write [once], and read [each pass] [GlobalSetup] public void Setup() @@ -93,13 +90,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) public void SeedData(int numblogs) { Blogs.AddRange( - Enumerable.Range(0, numblogs).Select(i => new Blog - { - Name = $"Blog{i}", - Url = $"blog{i}.blogs.net", - CreationTime = new DateTime(2020, 1, 1), - Rating = i % 5 - })); + Enumerable.Range(0, numblogs).Select( + i => new Blog + { + Name = $"Blog{i}", Url = $"blog{i}.blogs.net", CreationTime = new DateTime(2020, 1, 1), Rating = i % 5 + })); SaveChanges(); } } diff --git a/samples/core/Benchmarks/Benchmarks.csproj b/samples/core/Benchmarks/Benchmarks.csproj index d6295ac764..9bb8a15b75 100644 --- a/samples/core/Benchmarks/Benchmarks.csproj +++ b/samples/core/Benchmarks/Benchmarks.csproj @@ -7,7 +7,7 @@ - - + + diff --git a/samples/core/Benchmarks/DynamicallyConstructedQueries.cs b/samples/core/Benchmarks/DynamicallyConstructedQueries.cs index 09915ca152..84e556e458 100644 --- a/samples/core/Benchmarks/DynamicallyConstructedQueries.cs +++ b/samples/core/Benchmarks/DynamicallyConstructedQueries.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; using System.Linq; diff --git a/samples/core/Benchmarks/Inheritance.cs b/samples/core/Benchmarks/Inheritance.cs index e321c23941..549af1837f 100644 --- a/samples/core/Benchmarks/Inheritance.cs +++ b/samples/core/Benchmarks/Inheritance.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; using System.Linq; @@ -38,7 +35,7 @@ public void SetupTPT() } [Benchmark] - public static List TPH() + public List TPH() { using var context = new TPHContext(); @@ -46,7 +43,7 @@ public static List TPH() } [Benchmark] - public static List TPT() + public List TPT() { using var context = new TPTContext(); diff --git a/samples/core/Benchmarks/QueryTrackingBehavior.cs b/samples/core/Benchmarks/QueryTrackingBehavior.cs index 9dd490447a..d58aa51081 100644 --- a/samples/core/Benchmarks/QueryTrackingBehavior.cs +++ b/samples/core/Benchmarks/QueryTrackingBehavior.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; using System.Linq; @@ -30,7 +27,7 @@ public void Setup() } [Benchmark(Baseline = true)] - public static List AsTracking() + public List AsTracking() { using var context = new BloggingContext(); @@ -38,7 +35,7 @@ public static List AsTracking() } [Benchmark] - public static List AsNoTracking() + public List AsNoTracking() { using var context = new BloggingContext(); @@ -57,10 +54,8 @@ public static void SeedData(int numBlogs, int numPostsPerBlog) { using var context = new BloggingContext(); context.AddRange( - Enumerable.Range(0, numBlogs).Select(_ => new Blog - { - Posts = Enumerable.Range(0, numPostsPerBlog).Select(_ => new Post()).ToList() - })); + Enumerable.Range(0, numBlogs).Select( + _ => new Blog { Posts = Enumerable.Range(0, numPostsPerBlog).Select(_ => new Post()).ToList() })); context.SaveChanges(); } } diff --git a/samples/core/CascadeDeletes/CascadeDeletes.csproj b/samples/core/CascadeDeletes/CascadeDeletes.csproj index ed2d2155d9..24f01900ae 100644 --- a/samples/core/CascadeDeletes/CascadeDeletes.csproj +++ b/samples/core/CascadeDeletes/CascadeDeletes.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/samples/core/CascadeDeletes/OptionalDependentsSamples.cs b/samples/core/CascadeDeletes/OptionalDependentsSamples.cs index f11ead4733..1a2e32a411 100644 --- a/samples/core/CascadeDeletes/OptionalDependentsSamples.cs +++ b/samples/core/CascadeDeletes/OptionalDependentsSamples.cs @@ -16,11 +16,13 @@ public static void Optional_relationship_with_dependents_children_loaded() var deleteResults = Helpers.GatherData(c => c.Remove(c.Blogs.Include(e => e.Posts).Single())); var severResults = Helpers.GatherData(c => c.Blogs.Include(e => e.Posts).Single().Posts.Clear()); - Console.WriteLine($"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); + Console.WriteLine( + $"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); Console.WriteLine("|:------------------|------------------------------------------|----------------------------------------"); foreach (var deleteBehavior in DeleteBehaviors) { - Console.WriteLine($"| `{(deleteBehavior + "`").PadRight(16)} | {deleteResults[deleteBehavior].PadRight(40)} | {severResults[deleteBehavior]}"); + Console.WriteLine( + $"| `{(deleteBehavior + "`").PadRight(16)} | {deleteResults[deleteBehavior].PadRight(40)} | {severResults[deleteBehavior]}"); } Console.WriteLine(); @@ -33,7 +35,8 @@ public static void Optional_relationship_with_dependents_children_not_loaded() var deleteResults = Helpers.GatherData(c => c.Remove(c.Blogs.Single())); - Console.WriteLine($"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); + Console.WriteLine( + $"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); Console.WriteLine("|:------------------|------------------------------------------|----------------------------------------"); foreach (var deleteBehavior in DeleteBehaviors) { @@ -46,13 +49,8 @@ public static void Optional_relationship_with_dependents_children_not_loaded() public static DeleteBehavior[] DeleteBehaviors { get; } = { - DeleteBehavior.Cascade, - DeleteBehavior.Restrict, - DeleteBehavior.NoAction, - DeleteBehavior.SetNull, - DeleteBehavior.ClientSetNull, - DeleteBehavior.ClientCascade, - DeleteBehavior.ClientNoAction + DeleteBehavior.Cascade, DeleteBehavior.Restrict, DeleteBehavior.NoAction, DeleteBehavior.SetNull, + DeleteBehavior.ClientSetNull, DeleteBehavior.ClientCascade, DeleteBehavior.ClientNoAction }; #region Model diff --git a/samples/core/CascadeDeletes/Program.cs b/samples/core/CascadeDeletes/Program.cs index 8711db7b5e..9623a16faa 100644 --- a/samples/core/CascadeDeletes/Program.cs +++ b/samples/core/CascadeDeletes/Program.cs @@ -1,7 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; +using System; using DatabaseCycles; using IntroOptional; using IntroRequired; diff --git a/samples/core/CascadeDeletes/RequiredDependentsSamples.cs b/samples/core/CascadeDeletes/RequiredDependentsSamples.cs index 4815e26dab..6f4d3c8562 100644 --- a/samples/core/CascadeDeletes/RequiredDependentsSamples.cs +++ b/samples/core/CascadeDeletes/RequiredDependentsSamples.cs @@ -16,11 +16,13 @@ public static void Required_relationship_with_dependents_children_loaded() var deleteResults = Helpers.GatherData(c => c.Remove(c.Blogs.Include(e => e.Posts).Single())); var severResults = Helpers.GatherData(c => c.Blogs.Include(e => e.Posts).Single().Posts.Clear()); - Console.WriteLine($"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); + Console.WriteLine( + $"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); Console.WriteLine("|:------------------|------------------------------------------|----------------------------------------"); foreach (var deleteBehavior in DeleteBehaviors) { - Console.WriteLine($"| `{(deleteBehavior + "`").PadRight(16)} | {deleteResults[deleteBehavior].PadRight(40)} | {severResults[deleteBehavior]}"); + Console.WriteLine( + $"| `{(deleteBehavior + "`").PadRight(16)} | {deleteResults[deleteBehavior].PadRight(40)} | {severResults[deleteBehavior]}"); } Console.WriteLine(); @@ -33,7 +35,8 @@ public static void Required_relationship_with_dependents_children_not_loaded() var deleteResults = Helpers.GatherData(c => c.Remove(c.Blogs.Single())); - Console.WriteLine($"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); + Console.WriteLine( + $"| `{"DeleteBehavior".PadRight(16)} | {"On deleting principal/parent".PadRight(40)} | On severing from principal/parent"); Console.WriteLine("|:------------------|------------------------------------------|----------------------------------------"); foreach (var deleteBehavior in DeleteBehaviors) { @@ -46,13 +49,8 @@ public static void Required_relationship_with_dependents_children_not_loaded() public static DeleteBehavior[] DeleteBehaviors { get; } = { - DeleteBehavior.Cascade, - DeleteBehavior.Restrict, - DeleteBehavior.NoAction, - DeleteBehavior.SetNull, - DeleteBehavior.ClientSetNull, - DeleteBehavior.ClientCascade, - DeleteBehavior.ClientNoAction + DeleteBehavior.Cascade, DeleteBehavior.Restrict, DeleteBehavior.NoAction, DeleteBehavior.SetNull, + DeleteBehavior.ClientSetNull, DeleteBehavior.ClientCascade, DeleteBehavior.ClientNoAction }; #region Model diff --git a/samples/core/CascadeDeletes/WithDatabaseCycleSamples.cs b/samples/core/CascadeDeletes/WithDatabaseCycleSamples.cs index 2880189b66..c323b6717a 100644 --- a/samples/core/CascadeDeletes/WithDatabaseCycleSamples.cs +++ b/samples/core/CascadeDeletes/WithDatabaseCycleSamples.cs @@ -77,10 +77,7 @@ public static void PopulateDatabase() { using var context = new BlogsContext(quiet: true); - var person = new Person - { - Name = "ajcvickers" - }; + var person = new Person { Name = "ajcvickers" }; context.Add( new Blog diff --git a/samples/core/ChangeTracking/AccessingTrackedEntities/AccessingTrackedEntities.csproj b/samples/core/ChangeTracking/AccessingTrackedEntities/AccessingTrackedEntities.csproj index 160f93d52b..244fae190c 100644 --- a/samples/core/ChangeTracking/AccessingTrackedEntities/AccessingTrackedEntities.csproj +++ b/samples/core/ChangeTracking/AccessingTrackedEntities/AccessingTrackedEntities.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/ChangeTracking/AccessingTrackedEntities/Samples.cs b/samples/core/ChangeTracking/AccessingTrackedEntities/Samples.cs index 0a2bc7ff4b..23b4871696 100644 --- a/samples/core/ChangeTracking/AccessingTrackedEntities/Samples.cs +++ b/samples/core/ChangeTracking/AccessingTrackedEntities/Samples.cs @@ -237,11 +237,7 @@ public static void Work_with_all_properties_of_an_entity_2() { #region Work_with_all_properties_of_an_entity_2d - var blogDictionary = new Dictionary - { - ["Id"] = 1, - ["Name"] = "1unicorn2" - }; + var blogDictionary = new Dictionary { ["Id"] = 1, ["Name"] = "1unicorn2" }; context.Entry(blog).CurrentValues.SetValues(blogDictionary); #endregion diff --git a/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/AdditionalChangeTrackingFeatures.csproj b/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/AdditionalChangeTrackingFeatures.csproj index 160f93d52b..244fae190c 100644 --- a/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/AdditionalChangeTrackingFeatures.csproj +++ b/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/AdditionalChangeTrackingFeatures.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/Samples.cs b/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/Samples.cs index e5295edbf4..653b64fde3 100644 --- a/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/Samples.cs +++ b/samples/core/ChangeTracking/AdditionalChangeTrackingFeatures/Samples.cs @@ -23,11 +23,7 @@ public static void DbContext_verses_DbSet_methods_1() var tag = context.Tags.Single(e => e.Id == 1); var joinEntitySet = context.Set>("PostTag"); - var joinEntity = new Dictionary - { - ["PostId"] = post.Id, - ["TagId"] = tag.Id - }; + var joinEntity = new Dictionary { ["PostId"] = post.Id, ["TagId"] = tag.Id }; joinEntitySet.Add(joinEntity); Console.WriteLine(context.ChangeTracker.DebugView.LongView); @@ -68,11 +64,7 @@ public static void Temporary_values_2() Helpers.RecreateCleanDatabase(); #region Temporary_values_2 - var blogs = new List - { - new Blog { Id = -1, Name = ".NET Blog" }, - new Blog { Id = -2, Name = "Visual Studio Blog" } - }; + var blogs = new List { new Blog { Id = -1, Name = ".NET Blog" }, new Blog { Id = -2, Name = "Visual Studio Blog" } }; var posts = new List { @@ -155,7 +147,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -164,18 +157,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } @@ -243,10 +227,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .SharedTypeEntity>( "PostTag", b => - { - b.IndexerProperty("TagId"); - b.IndexerProperty("PostId"); - }); + { + b.IndexerProperty("TagId"); + b.IndexerProperty("PostId"); + }); modelBuilder.Entity() .HasMany(p => p.Tags) diff --git a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeDetectionAndNotifications.csproj b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeDetectionAndNotifications.csproj index cd38c85186..fd299873aa 100644 --- a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeDetectionAndNotifications.csproj +++ b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeDetectionAndNotifications.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeTrackingProxiesSamples.cs b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeTrackingProxiesSamples.cs index 64cfb2ee43..932633ff42 100644 --- a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeTrackingProxiesSamples.cs +++ b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/ChangeTrackingProxiesSamples.cs @@ -28,10 +28,10 @@ public static void Change_tracking_proxies_1() blog.Posts.Add( context.CreateProxy( p => - { - p.Title = "What’s next for System.Text.Json?"; - p.Content = ".NET 5.0 was released recently and has come with many..."; - })); + { + p.Title = "What’s next for System.Text.Json?"; + p.Content = ".NET 5.0 was released recently and has come with many..."; + })); Console.WriteLine(context.ChangeTracker.DebugView.LongView); #endregion @@ -57,42 +57,43 @@ public static void PopulateDatabase() context.AddRange( context.CreateProxy( b => - { - b.Name = ".NET Blog"; - b.Posts.Add( - context.CreateProxy( - p => - { - p.Title = "Announcing the Release of EF Core 5.0"; - p.Content = "Announcing the release of EF Core 5.0, a full featured cross-platform..."; - })); - b.Posts.Add( - context.CreateProxy( - p => - { - p.Title = "Announcing F# 5"; - p.Content = "F# 5 is the latest version of F#, the functional programming language..."; - })); - }), + { + b.Name = ".NET Blog"; + b.Posts.Add( + context.CreateProxy( + p => + { + p.Title = "Announcing the Release of EF Core 5.0"; + p.Content = "Announcing the release of EF Core 5.0, a full featured cross-platform..."; + })); + b.Posts.Add( + context.CreateProxy( + p => + { + p.Title = "Announcing F# 5"; + p.Content = "F# 5 is the latest version of F#, the functional programming language..."; + })); + }), context.CreateProxy( b => - { - b.Name = "Visual Studio Blog"; - b.Posts.Add( - context.CreateProxy( - p => - { - p.Title = "Disassembly improvements for optimized managed debugging"; - p.Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..."; - })); - b.Posts.Add( - context.CreateProxy( - p => - { - p.Title = "Database Profiling with Visual Studio"; - p.Content = "Examine when database queries were executed and measure how long the take using..."; - })); - })); + { + b.Name = "Visual Studio Blog"; + b.Posts.Add( + context.CreateProxy( + p => + { + p.Title = "Disassembly improvements for optimized managed debugging"; + p.Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..."; + })); + b.Posts.Add( + context.CreateProxy( + p => + { + p.Title = "Database Profiling with Visual Studio"; + p.Content = "Examine when database queries were executed and measure how long the take using..."; + })); + })); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationEntitiesSamples.cs b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationEntitiesSamples.cs index 903c901941..c4e0c590f4 100644 --- a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationEntitiesSamples.cs +++ b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationEntitiesSamples.cs @@ -29,8 +29,7 @@ public static void Notification_entities_1() blog.Posts.Add( new Post { - Title = "What’s next for System.Text.Json?", - Content = ".NET 5.0 was released recently and has come with many..." + Title = "What’s next for System.Text.Json?", Content = ".NET 5.0 was released recently and has come with many..." }); Console.WriteLine(context.ChangeTracker.DebugView.LongView); @@ -80,7 +79,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { diff --git a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationWithBaseSamples.cs b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationWithBaseSamples.cs index 8a16b69105..1e582ed082 100644 --- a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationWithBaseSamples.cs +++ b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/NotificationWithBaseSamples.cs @@ -30,8 +30,7 @@ public static void Notification_entities_2() blog.Posts.Add( new Post { - Title = "What’s next for System.Text.Json?", - Content = ".NET 5.0 was released recently and has come with many..." + Title = "What’s next for System.Text.Json?", Content = ".NET 5.0 was released recently and has come with many..." }); Console.WriteLine(context.ChangeTracker.DebugView.LongView); @@ -81,7 +80,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { diff --git a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/SnapshotSamples.cs b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/SnapshotSamples.cs index b2d1690fdd..1facae3966 100644 --- a/samples/core/ChangeTracking/ChangeDetectionAndNotifications/SnapshotSamples.cs +++ b/samples/core/ChangeTracking/ChangeDetectionAndNotifications/SnapshotSamples.cs @@ -27,8 +27,7 @@ public static void Snapshot_change_tracking_1() blog.Posts.Add( new Post { - Title = "What’s next for System.Text.Json?", - Content = ".NET 5.0 was released recently and has come with many..." + Title = "What’s next for System.Text.Json?", Content = ".NET 5.0 was released recently and has come with many..." }); Console.WriteLine(context.ChangeTracker.DebugView.LongView); @@ -110,7 +109,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { diff --git a/samples/core/ChangeTracking/ChangeTrackerDebugging/ChangeTrackerDebugging.csproj b/samples/core/ChangeTracking/ChangeTrackerDebugging/ChangeTrackerDebugging.csproj index 160f93d52b..244fae190c 100644 --- a/samples/core/ChangeTracking/ChangeTrackerDebugging/ChangeTrackerDebugging.csproj +++ b/samples/core/ChangeTracking/ChangeTrackerDebugging/ChangeTrackerDebugging.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/ChangeTracking/ChangeTrackerDebugging/Samples.cs b/samples/core/ChangeTracking/ChangeTrackerDebugging/Samples.cs index af1a1eba8d..e9f16413be 100644 --- a/samples/core/ChangeTracking/ChangeTrackerDebugging/Samples.cs +++ b/samples/core/ChangeTracking/ChangeTrackerDebugging/Samples.cs @@ -133,7 +133,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -146,21 +147,9 @@ public static void PopulateDatabase() var tags = new[] { - new Tag - { - Text = ".NET", - Posts = { blogs[0].Posts[0], blogs[0].Posts[1] } - }, - new Tag - { - Text = "Visual Studio", - Posts = { blogs[1].Posts[0], blogs[1].Posts[1] } - }, - new Tag - { - Text = "EF Core", - Posts = { blogs[0].Posts[0] } - } + new Tag { Text = ".NET", Posts = { blogs[0].Posts[0], blogs[0].Posts[1] } }, + new Tag { Text = "Visual Studio", Posts = { blogs[1].Posts[0], blogs[1].Posts[1] } }, + new Tag { Text = "EF Core", Posts = { blogs[0].Posts[0] } } }; context.AddRange(blogs); diff --git a/samples/core/ChangeTracking/ChangeTrackingInEFCore/ChangeTrackingInEFCore.csproj b/samples/core/ChangeTracking/ChangeTrackingInEFCore/ChangeTrackingInEFCore.csproj index 160f93d52b..244fae190c 100644 --- a/samples/core/ChangeTracking/ChangeTrackingInEFCore/ChangeTrackingInEFCore.csproj +++ b/samples/core/ChangeTracking/ChangeTrackingInEFCore/ChangeTrackingInEFCore.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/ChangeTracking/ChangeTrackingInEFCore/ExplicitKeysSamples.cs b/samples/core/ChangeTracking/ChangeTrackingInEFCore/ExplicitKeysSamples.cs index 4a13e67245..4de7b96538 100644 --- a/samples/core/ChangeTracking/ChangeTrackingInEFCore/ExplicitKeysSamples.cs +++ b/samples/core/ChangeTracking/ChangeTrackingInEFCore/ExplicitKeysSamples.cs @@ -20,11 +20,7 @@ public static void Inserting_new_entities_1() #region Inserting_new_entities_1 context.Add( - new Blog - { - Id = 1, - Name = ".NET Blog", - }); + new Blog { Id = 1, Name = ".NET Blog", }); #endregion Console.WriteLine("Before SaveChanges:"); @@ -94,11 +90,7 @@ public static void Attaching_existing_entities_1() #region Attaching_existing_entities_1 context.Attach( - new Blog - { - Id = 1, - Name = ".NET Blog", - }); + new Blog { Id = 1, Name = ".NET Blog", }); #endregion Console.WriteLine("Before SaveChanges:"); @@ -169,11 +161,7 @@ public static void Updating_existing_entities_1() #region Updating_existing_entities_1 context.Update( - new Blog - { - Id = 1, - Name = ".NET Blog", - }); + new Blog { Id = 1, Name = ".NET Blog", }); #endregion Console.WriteLine("Before SaveChanges:"); @@ -244,10 +232,7 @@ public static void Deleting_existing_entities_1() #region Deleting_existing_entities_1 context.Remove( - new Post - { - Id = 2 - }); + new Post { Id = 2 }); #endregion Console.WriteLine("Before SaveChanges:"); diff --git a/samples/core/ChangeTracking/ChangeTrackingInEFCore/GeneratedKeysSamples.cs b/samples/core/ChangeTracking/ChangeTrackingInEFCore/GeneratedKeysSamples.cs index f24236e59c..d27997359c 100644 --- a/samples/core/ChangeTracking/ChangeTrackingInEFCore/GeneratedKeysSamples.cs +++ b/samples/core/ChangeTracking/ChangeTrackingInEFCore/GeneratedKeysSamples.cs @@ -83,8 +83,7 @@ public static void Query_then_insert_update_and_delete_1() blog.Posts.Add( new Post { - Title = "What’s next for System.Text.Json?", - Content = ".NET 5.0 was released recently and has come with many..." + Title = "What’s next for System.Text.Json?", Content = ".NET 5.0 was released recently and has come with many..." }); // Mark an existing Post as Deleted @@ -276,26 +275,26 @@ public static void UpdateBlog(Blog blog) context.ChangeTracker.TrackGraph( blog, node => - { - var propertyEntry = node.Entry.Property("Id"); - var keyValue = (int)propertyEntry.CurrentValue; + { + var propertyEntry = node.Entry.Property("Id"); + var keyValue = (int)propertyEntry.CurrentValue; - if (keyValue == 0) - { - node.Entry.State = EntityState.Added; - } - else if (keyValue < 0) - { - propertyEntry.CurrentValue = -keyValue; - node.Entry.State = EntityState.Deleted; - } - else - { - node.Entry.State = EntityState.Modified; - } + if (keyValue == 0) + { + node.Entry.State = EntityState.Added; + } + else if (keyValue < 0) + { + propertyEntry.CurrentValue = -keyValue; + node.Entry.State = EntityState.Deleted; + } + else + { + node.Entry.State = EntityState.Modified; + } - Console.WriteLine($"Tracking {node.Entry.Metadata.DisplayName()} with key value {keyValue} as {node.Entry.State}"); - }); + Console.WriteLine($"Tracking {node.Entry.Metadata.DisplayName()} with key value {keyValue} as {node.Entry.State}"); + }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ChangingFKsAndNavigations.csproj b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ChangingFKsAndNavigations.csproj index 160f93d52b..244fae190c 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ChangingFKsAndNavigations.csproj +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ChangingFKsAndNavigations.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityAndSkipsSamples.cs b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityAndSkipsSamples.cs index 966dcf13d9..4b50fe23ae 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityAndSkipsSamples.cs +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityAndSkipsSamples.cs @@ -118,7 +118,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -127,18 +128,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntitySamples.cs b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntitySamples.cs index 69a17f6a4a..bd7a8a2ece 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntitySamples.cs +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntitySamples.cs @@ -97,7 +97,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -106,18 +107,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithPayloadSamples.cs b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithPayloadSamples.cs index b1cbf5702b..db8d77041f 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithPayloadSamples.cs +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithPayloadSamples.cs @@ -73,7 +73,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -82,18 +83,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithStringPayloadSamples.cs b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithStringPayloadSamples.cs index 104f8e01ec..88f919a0da 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithStringPayloadSamples.cs +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/ExplicitJoinEntityWithStringPayloadSamples.cs @@ -53,12 +53,7 @@ public static void Many_to_many_relationships_9() var tag = context.Tags.Single(e => e.Id == 1); context.Add( - new PostTag - { - PostId = post.Id, - TagId = tag.Id, - TaggedBy = "ajcvickers" - }); + new PostTag { PostId = post.Id, TagId = tag.Id, TaggedBy = "ajcvickers" }); context.SaveChanges(); @@ -109,7 +104,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -118,18 +114,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/OptionalRelationshipsSamples.cs b/samples/core/ChangeTracking/ChangingFKsAndNavigations/OptionalRelationshipsSamples.cs index 9a21497c4b..b9a518d33c 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/OptionalRelationshipsSamples.cs +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/OptionalRelationshipsSamples.cs @@ -338,7 +338,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -347,18 +348,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/ChangingFKsAndNavigations/RequiredRelationshipsSamples.cs b/samples/core/ChangeTracking/ChangingFKsAndNavigations/RequiredRelationshipsSamples.cs index 9f0597adc7..a12809551b 100644 --- a/samples/core/ChangeTracking/ChangingFKsAndNavigations/RequiredRelationshipsSamples.cs +++ b/samples/core/ChangeTracking/ChangingFKsAndNavigations/RequiredRelationshipsSamples.cs @@ -192,7 +192,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { @@ -201,18 +202,9 @@ public static void PopulateDatabase() }, } }, - new Tag - { - Text = ".NET" - }, - new Tag - { - Text = "Visual Studio" - }, - new Tag - { - Text = "EF Core" - }); + new Tag { Text = ".NET" }, + new Tag { Text = "Visual Studio" }, + new Tag { Text = "EF Core" }); context.SaveChanges(); } diff --git a/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionInEFCore.csproj b/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionInEFCore.csproj index ab607cf613..7116715d86 100644 --- a/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionInEFCore.csproj +++ b/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionInEFCore.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionSamples.cs b/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionSamples.cs index 52c35a3f38..546620184f 100644 --- a/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionSamples.cs +++ b/samples/core/ChangeTracking/IdentityResolutionInEFCore/IdentityResolutionSamples.cs @@ -45,12 +45,7 @@ public static void Updating_an_entity_1() Helpers.PopulateDatabase(); UpdateFromHttpPost1( - new Blog - { - Id = 1, - Name = ".NET Blog (All new!)", - Summary = "Posts about .NET" - }); + new Blog { Id = 1, Name = ".NET Blog (All new!)", Summary = "Posts about .NET" }); Console.WriteLine(); } @@ -75,12 +70,7 @@ public static void Updating_an_entity_2() Helpers.PopulateDatabase(); UpdateFromHttpPost2( - new Blog - { - Id = 1, - Name = ".NET Blog (All new!)", - Summary = "Posts about .NET" - }); + new Blog { Id = 1, Name = ".NET Blog (All new!)", Summary = "Posts about .NET" }); Console.WriteLine(); } @@ -108,12 +98,7 @@ public static void Updating_an_entity_3() Helpers.PopulateDatabase(); UpdateFromHttpPost3( - new Blog - { - Id = 1, - Name = ".NET Blog (All new!)", - Summary = "Posts about .NET" - }); + new Blog { Id = 1, Name = ".NET Blog (All new!)", Summary = "Posts about .NET" }); Console.WriteLine(); } @@ -140,12 +125,7 @@ public static void Updating_an_entity_4() Helpers.PopulateDatabase(); UpdateFromHttpPost4( - new BlogDto - { - Id = 1, - Name = ".NET Blog (All new!)", - Summary = "Posts about .NET" - }); + new BlogDto { Id = 1, Name = ".NET Blog (All new!)", Summary = "Posts about .NET" }); Console.WriteLine(); } @@ -172,12 +152,7 @@ public static void Updating_an_entity_5() Helpers.PopulateDatabase(); UpdateFromHttpPost5( - new Dictionary - { - ["Id"] = 1, - ["Name"] = ".NET Blog (All new!)", - ["Summary"] = "Posts about .NET" - }); + new Dictionary { ["Id"] = 1, ["Name"] = ".NET Blog (All new!)", ["Summary"] = "Posts about .NET" }); Console.WriteLine(); } @@ -204,18 +179,8 @@ public static void Updating_an_entity_6() Helpers.PopulateDatabase(); UpdateFromHttpPost6( - new Blog - { - Id = 1, - Name = ".NET Blog (All new!)", - Summary = "Posts about .NET" - }, - new Dictionary - { - ["Id"] = 1, - ["Name"] = ".NET Blog", - ["Summary"] = "Posts about .NET" - }); + new Blog { Id = 1, Name = ".NET Blog (All new!)", Summary = "Posts about .NET" }, + new Dictionary { ["Id"] = 1, ["Name"] = ".NET Blog", ["Summary"] = "Posts about .NET" }); Console.WriteLine(); } diff --git a/samples/core/ChangeTracking/IdentityResolutionInEFCore/SerializedGraphExamples.cs b/samples/core/ChangeTracking/IdentityResolutionInEFCore/SerializedGraphExamples.cs index 8420cba23f..016b8d6bc5 100644 --- a/samples/core/ChangeTracking/IdentityResolutionInEFCore/SerializedGraphExamples.cs +++ b/samples/core/ChangeTracking/IdentityResolutionInEFCore/SerializedGraphExamples.cs @@ -27,11 +27,7 @@ public static void Attaching_a_serialized_graph_1() var serialized = JsonConvert.SerializeObject( blogs, - new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - Formatting = Formatting.Indented - }); + new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); Console.WriteLine(serialized); #endregion @@ -70,11 +66,7 @@ public static void Attaching_a_serialized_graph_2() var serialized = JsonConvert.SerializeObject( posts, - new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - Formatting = Formatting.Indented - }); + new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); Console.WriteLine(serialized); #endregion @@ -120,8 +112,7 @@ public static void Attaching_a_serialized_graph_3() posts, new JsonSerializerSettings { - PreserveReferencesHandling = PreserveReferencesHandling.All, - Formatting = Formatting.Indented + PreserveReferencesHandling = PreserveReferencesHandling.All, Formatting = Formatting.Indented }); #endregion @@ -158,11 +149,7 @@ public static void Attaching_a_serialized_graph_4() #region Attaching_a_serialized_graph_4 var serialized = JsonSerializer.Serialize( - posts, new JsonSerializerOptions - { - ReferenceHandler = ReferenceHandler.Preserve, - WriteIndented = true - }); + posts, new JsonSerializerOptions { ReferenceHandler = ReferenceHandler.Preserve, WriteIndented = true }); #endregion Console.WriteLine(serialized); @@ -184,11 +171,7 @@ public static void Attaching_a_serialized_graph_5() var serialized = JsonConvert.SerializeObject( posts, - new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - Formatting = Formatting.Indented - }); + new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); Console.WriteLine(serialized); @@ -208,26 +191,26 @@ public static void UpdatePostsFromJsonWithIdentityResolution(string json) { context.ChangeTracker.TrackGraph( post, node => + { + var keyValue = node.Entry.Property("Id").CurrentValue; + var entityType = node.Entry.Metadata; + + var existingEntity = node.Entry.Context.ChangeTracker.Entries() + .FirstOrDefault( + e => Equals(e.Metadata, entityType) + && Equals(e.Property("Id").CurrentValue, keyValue)); + + if (existingEntity == null) + { + Console.WriteLine($"Tracking {entityType.DisplayName()} entity with key value {keyValue}"); + + node.Entry.State = EntityState.Modified; + } + else { - var keyValue = node.Entry.Property("Id").CurrentValue; - var entityType = node.Entry.Metadata; - - var existingEntity = node.Entry.Context.ChangeTracker.Entries() - .FirstOrDefault( - e => Equals(e.Metadata, entityType) - && Equals(e.Property("Id").CurrentValue, keyValue)); - - if (existingEntity == null) - { - Console.WriteLine($"Tracking {entityType.DisplayName()} entity with key value {keyValue}"); - - node.Entry.State = EntityState.Modified; - } - else - { - Console.WriteLine($"Discarding duplicate {entityType.DisplayName()} entity with key value {keyValue}"); - } - }); + Console.WriteLine($"Discarding duplicate {entityType.DisplayName()} entity with key value {keyValue}"); + } + }); } context.SaveChanges(); @@ -277,7 +260,8 @@ public static void PopulateDatabase() new Post { Title = "Disassembly improvements for optimized managed debugging", - Content = "If you are focused on squeezing out the last bits of performance for your .NET service or..." + Content = + "If you are focused on squeezing out the last bits of performance for your .NET service or..." }, new Post { diff --git a/samples/core/CompiledQueries/CompiledQueries.csproj b/samples/core/CompiledQueries/CompiledQueries.csproj index ff45c3377a..64f9809c8d 100644 --- a/samples/core/CompiledQueries/CompiledQueries.csproj +++ b/samples/core/CompiledQueries/CompiledQueries.csproj @@ -5,6 +5,6 @@ Samples - + diff --git a/samples/core/CompiledQueries/Model/AdventureWorksContext.cs b/samples/core/CompiledQueries/Model/AdventureWorksContext.cs index 9765734b4e..3a2e544f82 100644 --- a/samples/core/CompiledQueries/Model/AdventureWorksContext.cs +++ b/samples/core/CompiledQueries/Model/AdventureWorksContext.cs @@ -1,7 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; namespace Samples.Model { @@ -17,31 +14,30 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity( entity => - { - entity.ToTable("Customer", "Sales"); + { + entity.ToTable("Customer", "Sales"); - entity.HasIndex(e => e.AccountNumber) - .HasName("AK_Customer_AccountNumber") - .IsUnique(); + entity.HasIndex(e => e.AccountNumber) + .HasDatabaseName("AK_Customer_AccountNumber") + .IsUnique(); - entity.HasIndex(e => e.TerritoryID) - .HasName("IX_Customer_TerritoryID"); + entity.HasIndex(e => e.TerritoryID) + .HasDatabaseName("IX_Customer_TerritoryID"); - entity.HasIndex(e => e.rowguid) - .HasName("AK_Customer_rowguid") - .IsUnique(); + entity.HasIndex(e => e.rowguid) + .HasDatabaseName("AK_Customer_rowguid") + .IsUnique(); - entity.Property(e => e.AccountNumber) - .IsRequired() - .HasColumnType("varchar(10)") - .ValueGeneratedOnAddOrUpdate(); + entity.Property(e => e.AccountNumber) + .IsRequired() + .HasColumnType("varchar(10)"); - entity.Property(e => e.ModifiedDate) - .HasColumnType("datetime") - .HasDefaultValueSql("getdate()"); + entity.Property(e => e.ModifiedDate) + .HasColumnType("datetime") + .HasDefaultValueSql("getdate()"); - entity.Property(e => e.rowguid).HasDefaultValueSql("newid()"); - }); + entity.Property(e => e.rowguid).HasDefaultValueSql("newid()"); + }); } public virtual DbSet Customers { get; set; } diff --git a/samples/core/CompiledQueries/Model/Customer.cs b/samples/core/CompiledQueries/Model/Customer.cs index d16885e072..3f79e12905 100644 --- a/samples/core/CompiledQueries/Model/Customer.cs +++ b/samples/core/CompiledQueries/Model/Customer.cs @@ -1,7 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; +using System; namespace Samples.Model { diff --git a/samples/core/CompiledQueries/Program.cs b/samples/core/CompiledQueries/Program.cs index 69c8db20e2..3c0a5ab4b5 100644 --- a/samples/core/CompiledQueries/Program.cs +++ b/samples/core/CompiledQueries/Program.cs @@ -10,6 +10,19 @@ public class Program { private static void Main() { + using (var db = new AdventureWorksContext()) + { + db.Database.EnsureDeleted(); + db.Database.EnsureCreated(); + + foreach (var accountNumber in GetAccountNumbers(2000)) + { + db.Add(new Customer { AccountNumber = accountNumber, }); + } + + db.SaveChanges(); + } + // Warmup using (var db = new AdventureWorksContext()) { @@ -18,34 +31,35 @@ private static void Main() RunTest( accountNumbers => + { + using (var db = new AdventureWorksContext()) { - using (var db = new AdventureWorksContext()) + foreach (var id in accountNumbers) { - foreach (var id in accountNumbers) - { - // Use a regular auto-compiled query - var customer = db.Customers.Single(c => c.AccountNumber == id); - } + // Use a regular auto-compiled query + var customer = db.Customers.Single(c => c.AccountNumber == id); } - }, + } + }, name: "Regular"); RunTest( accountNumbers => - { - // Create an explicit compiled query - var query = EF.CompileQuery((AdventureWorksContext db, string id) - => db.Customers.Single(c => c.AccountNumber == id)); + { + // Create an explicit compiled query + var query = EF.CompileQuery( + (AdventureWorksContext db, string id) + => db.Customers.Single(c => c.AccountNumber == id)); - using (var db = new AdventureWorksContext()) + using (var db = new AdventureWorksContext()) + { + foreach (var id in accountNumbers) { - foreach (var id in accountNumbers) - { - // Invoke the compiled query - query(db, id); - } + // Invoke the compiled query + query(db, id); } - }, + } + }, name: "Compiled"); } diff --git a/samples/core/Cosmos/Cosmos.csproj b/samples/core/Cosmos/Cosmos.csproj index 5d2d0c62dc..9f2ed59d9f 100644 --- a/samples/core/Cosmos/Cosmos.csproj +++ b/samples/core/Cosmos/Cosmos.csproj @@ -6,7 +6,7 @@ - + diff --git a/samples/core/Cosmos/ModelBuilding/OptionsContext.cs b/samples/core/Cosmos/ModelBuilding/OptionsContext.cs index 6f2e287ab4..58cc78a45b 100644 --- a/samples/core/Cosmos/ModelBuilding/OptionsContext.cs +++ b/samples/core/Cosmos/ModelBuilding/OptionsContext.cs @@ -1,7 +1,7 @@ -using Microsoft.Azure.Cosmos; -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Net; +using Microsoft.Azure.Cosmos; +using Microsoft.EntityFrameworkCore; namespace Cosmos.ModelBuilding { @@ -10,21 +10,21 @@ public class OptionsContext : DbContext #region Configuration protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseCosmos( - "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", - databaseName: "OptionsDB", - options => - { - options.ConnectionMode(ConnectionMode.Gateway); - options.WebProxy(new WebProxy()); - options.LimitToEndpoint(); - options.Region(Regions.AustraliaCentral); - options.GatewayModeMaxConnectionLimit(32); - options.MaxRequestsPerTcpConnection(8); - options.MaxTcpConnectionsPerEndpoint(16); - options.IdleTcpConnectionTimeout(TimeSpan.FromMinutes(1)); - options.OpenTcpConnectionTimeout(TimeSpan.FromMinutes(1)); - options.RequestTimeout(TimeSpan.FromMinutes(1)); - }); + "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", + databaseName: "OptionsDB", + options => + { + options.ConnectionMode(ConnectionMode.Gateway); + options.WebProxy(new WebProxy()); + options.LimitToEndpoint(); + options.Region(Regions.AustraliaCentral); + options.GatewayModeMaxConnectionLimit(32); + options.MaxRequestsPerTcpConnection(8); + options.MaxTcpConnectionsPerEndpoint(16); + options.IdleTcpConnectionTimeout(TimeSpan.FromMinutes(1)); + options.OpenTcpConnectionTimeout(TimeSpan.FromMinutes(1)); + options.RequestTimeout(TimeSpan.FromMinutes(1)); + }); #endregion } } diff --git a/samples/core/Cosmos/ModelBuilding/OrderContext.cs b/samples/core/Cosmos/ModelBuilding/OrderContext.cs index 1b2bf42053..a113818333 100644 --- a/samples/core/Cosmos/ModelBuilding/OrderContext.cs +++ b/samples/core/Cosmos/ModelBuilding/OrderContext.cs @@ -10,9 +10,9 @@ public class OrderContext : DbContext #region Configuration protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseCosmos( - "https://localhost:8081", - "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", - databaseName: "OrdersDB"); + "https://localhost:8081", + "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", + databaseName: "OrdersDB"); #endregion protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/samples/core/Cosmos/ModelBuilding/Sample.cs b/samples/core/Cosmos/ModelBuilding/Sample.cs index c9bf7d96f8..65fcf2f0a6 100644 --- a/samples/core/Cosmos/ModelBuilding/Sample.cs +++ b/samples/core/Cosmos/ModelBuilding/Sample.cs @@ -1,8 +1,8 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; namespace Cosmos.ModelBuilding { @@ -20,12 +20,11 @@ public static async Task Run() await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); - context.Add(new Order - { - Id = 1, - ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, - PartitionKey = "1" - }); + context.Add( + new Order + { + Id = 1, ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, PartitionKey = "1" + }); await context.SaveChangesAsync(); } @@ -41,12 +40,11 @@ public static async Task Run() #region PartitionKey using (var context = new OrderContext()) { - context.Add(new Order - { - Id = 2, - ShippingAddress = new StreetAddress { City = "New York", Street = "11 Wall Street" }, - PartitionKey = "2" - }); + context.Add( + new Order + { + Id = 2, ShippingAddress = new StreetAddress { City = "New York", Street = "11 Wall Street" }, PartitionKey = "2" + }); await context.SaveChangesAsync(); } @@ -64,10 +62,11 @@ public static async Task Run() var distributor = new Distributor { Id = 1, - ShippingCenters = new HashSet { - new StreetAddress { City = "Phoenix", Street = "500 S 48th Street" }, - new StreetAddress { City = "Anaheim", Street = "5650 Dolly Ave" } - } + ShippingCenters = new HashSet + { + new StreetAddress { City = "Phoenix", Street = "500 S 48th Street" }, + new StreetAddress { City = "Anaheim", Street = "5650 Dolly Ave" } + } }; using (var context = new OrderContext()) @@ -87,7 +86,8 @@ public static async Task Run() var addressEntry = context.Entry(firstDistributor.ShippingCenters.First()); var addressPKProperties = addressEntry.Metadata.FindPrimaryKey().Properties; - Console.WriteLine($"First shipping center PK: ({addressEntry.Property(addressPKProperties[0].Name).CurrentValue}, {addressEntry.Property(addressPKProperties[1].Name).CurrentValue})"); + Console.WriteLine( + $"First shipping center PK: ({addressEntry.Property(addressPKProperties[0].Name).CurrentValue}, {addressEntry.Property(addressPKProperties[1].Name).CurrentValue})"); Console.WriteLine(); } #endregion diff --git a/samples/core/Cosmos/Program.cs b/samples/core/Cosmos/Program.cs index 8c1f6a16ba..2f631fded8 100644 --- a/samples/core/Cosmos/Program.cs +++ b/samples/core/Cosmos/Program.cs @@ -1,12 +1,13 @@ using System.Threading.Tasks; +using Cosmos.ModelBuilding; namespace Cosmos { public class Program { - static async Task Main() + private static async Task Main() { - await ModelBuilding.Sample.Run(); + await Sample.Run(); await UnstructuredData.Sample.Run(); } } diff --git a/samples/core/Cosmos/UnstructuredData/Sample.cs b/samples/core/Cosmos/UnstructuredData/Sample.cs index a2575d082e..423a0d898f 100644 --- a/samples/core/Cosmos/UnstructuredData/Sample.cs +++ b/samples/core/Cosmos/UnstructuredData/Sample.cs @@ -1,10 +1,10 @@ -using Cosmos.ModelBuilding; +using System; +using System.Linq; +using System.Threading.Tasks; +using Cosmos.ModelBuilding; using Microsoft.Azure.Cosmos; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json.Linq; -using System; -using System.Linq; -using System.Threading.Tasks; namespace Cosmos.UnstructuredData { @@ -24,9 +24,7 @@ public static async Task Run() var order = new Order { - Id = 1, - ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, - PartitionKey = "1" + Id = 1, ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, PartitionKey = "1" }; context.Add(order); diff --git a/samples/core/DbContextPooling/DbContextPooling.csproj b/samples/core/DbContextPooling/DbContextPooling.csproj index ff45c3377a..64f9809c8d 100644 --- a/samples/core/DbContextPooling/DbContextPooling.csproj +++ b/samples/core/DbContextPooling/DbContextPooling.csproj @@ -5,6 +5,6 @@ Samples - + diff --git a/samples/core/GetStarted/EFGetStarted.csproj b/samples/core/GetStarted/EFGetStarted.csproj index f3d5280a8c..3e7a82bfe6 100644 --- a/samples/core/GetStarted/EFGetStarted.csproj +++ b/samples/core/GetStarted/EFGetStarted.csproj @@ -7,8 +7,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/core/GetStarted/Migrations/20190917222642_InitialCreate.cs b/samples/core/GetStarted/Migrations/20190917222642_InitialCreate.cs index f6a1809b76..fd6529ed9f 100644 --- a/samples/core/GetStarted/Migrations/20190917222642_InitialCreate.cs +++ b/samples/core/GetStarted/Migrations/20190917222642_InitialCreate.cs @@ -14,10 +14,7 @@ protected override void Up(MigrationBuilder migrationBuilder) .Annotation("Sqlite:Autoincrement", true), Url = table.Column(nullable: true) }, - constraints: table => - { - table.PrimaryKey("PK_Blogs", x => x.BlogId); - }); + constraints: table => { table.PrimaryKey("PK_Blogs", x => x.BlogId); }); migrationBuilder.CreateTable( name: "Posts", diff --git a/samples/core/GetStarted/Migrations/BloggingContextModelSnapshot.cs b/samples/core/GetStarted/Migrations/BloggingContextModelSnapshot.cs index 56a150c267..7ac7b08817 100644 --- a/samples/core/GetStarted/Migrations/BloggingContextModelSnapshot.cs +++ b/samples/core/GetStarted/Migrations/BloggingContextModelSnapshot.cs @@ -1,13 +1,10 @@ -// -using EFGetStarted; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EFGetStarted.Migrations { [DbContext(typeof(BloggingContext))] - partial class BloggingContextModelSnapshot : ModelSnapshot + internal class BloggingContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -15,7 +12,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder .HasAnnotation("ProductVersion", "3.0.0-rc1.19456.14"); - modelBuilder.Entity("EFGetStarted.Blog", b => + modelBuilder.Entity( + "EFGetStarted.Blog", b => { b.Property("BlogId") .ValueGeneratedOnAdd() @@ -29,7 +27,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Blogs"); }); - modelBuilder.Entity("EFGetStarted.Post", b => + modelBuilder.Entity( + "EFGetStarted.Post", b => { b.Property("PostId") .ValueGeneratedOnAdd() @@ -51,7 +50,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Posts"); }); - modelBuilder.Entity("EFGetStarted.Post", b => + modelBuilder.Entity( + "EFGetStarted.Post", b => { b.HasOne("EFGetStarted.Blog", "Blog") .WithMany("Posts") diff --git a/samples/core/GetStarted/Program.cs b/samples/core/GetStarted/Program.cs index 0ed347fcbe..2f3c8a80cb 100644 --- a/samples/core/GetStarted/Program.cs +++ b/samples/core/GetStarted/Program.cs @@ -3,12 +3,14 @@ namespace EFGetStarted { - class Program + internal class Program { - static void Main() + private static void Main() { using (var db = new BloggingContext()) { + // Note: This sample requires the database to be created before running. + // Create Console.WriteLine("Inserting a new blog"); db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" }); @@ -24,11 +26,7 @@ static void Main() Console.WriteLine("Updating the blog and adding a post"); blog.Url = "https://devblogs.microsoft.com/dotnet"; blog.Posts.Add( - new Post - { - Title = "Hello World", - Content = "I wrote an app using EF Core!" - }); + new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" }); db.SaveChanges(); // Delete diff --git a/samples/core/Intro/Intro.csproj b/samples/core/Intro/Intro.csproj index 509155d827..b525a16e58 100644 --- a/samples/core/Intro/Intro.csproj +++ b/samples/core/Intro/Intro.csproj @@ -7,8 +7,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/core/Intro/Migrations/20191019191556_InitialCreate.cs b/samples/core/Intro/Migrations/20191019191556_InitialCreate.cs index 635b8ebd56..864f5581ca 100644 --- a/samples/core/Intro/Migrations/20191019191556_InitialCreate.cs +++ b/samples/core/Intro/Migrations/20191019191556_InitialCreate.cs @@ -15,10 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Url = table.Column(nullable: true), Rating = table.Column(nullable: false) }, - constraints: table => - { - table.PrimaryKey("PK_Blogs", x => x.BlogId); - }); + constraints: table => { table.PrimaryKey("PK_Blogs", x => x.BlogId); }); migrationBuilder.CreateTable( name: "Posts", diff --git a/samples/core/Intro/Migrations/BloggingContextModelSnapshot.cs b/samples/core/Intro/Migrations/BloggingContextModelSnapshot.cs index 5f5db5a6cd..cd48a28e3f 100644 --- a/samples/core/Intro/Migrations/BloggingContextModelSnapshot.cs +++ b/samples/core/Intro/Migrations/BloggingContextModelSnapshot.cs @@ -1,14 +1,11 @@ -// -using Intro; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Intro.Migrations { [DbContext(typeof(BloggingContext))] - partial class BloggingContextModelSnapshot : ModelSnapshot + internal class BloggingContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -18,7 +15,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("Intro.Blog", b => + modelBuilder.Entity( + "Intro.Blog", b => { b.Property("BlogId") .ValueGeneratedOnAdd() @@ -36,7 +34,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Blogs"); }); - modelBuilder.Entity("Intro.Post", b => + modelBuilder.Entity( + "Intro.Post", b => { b.Property("PostId") .ValueGeneratedOnAdd() @@ -59,7 +58,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Posts"); }); - modelBuilder.Entity("Intro.Post", b => + modelBuilder.Entity( + "Intro.Post", b => { b.HasOne("Intro.Blog", "Blog") .WithMany("Posts") diff --git a/samples/core/Intro/Model.cs b/samples/core/Intro/Model.cs index 9f0cceb6ca..7fa16340ab 100644 --- a/samples/core/Intro/Model.cs +++ b/samples/core/Intro/Model.cs @@ -1,5 +1,5 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace Intro { diff --git a/samples/core/Intro/Program.cs b/samples/core/Intro/Program.cs index 20b91581d1..0f63ca0d57 100644 --- a/samples/core/Intro/Program.cs +++ b/samples/core/Intro/Program.cs @@ -1,12 +1,19 @@ -using System; -using System.Linq; +using System.Linq; +using Microsoft.EntityFrameworkCore; namespace Intro { - class Program + internal class Program { - static void Main() + private static void Main() { + using (var db = new BloggingContext()) + { + // Remove these lines if you are running migrations from the command line + db.Database.EnsureDeleted(); + db.Database.Migrate(); + } + #region Querying using (var db = new BloggingContext()) { diff --git a/samples/core/KeylessEntityTypes/KeylessEntityTypes.csproj b/samples/core/KeylessEntityTypes/KeylessEntityTypes.csproj index b992717cfa..dd9d9a91ee 100644 --- a/samples/core/KeylessEntityTypes/KeylessEntityTypes.csproj +++ b/samples/core/KeylessEntityTypes/KeylessEntityTypes.csproj @@ -5,7 +5,7 @@ Samples - - + + diff --git a/samples/core/KeylessEntityTypes/Program.cs b/samples/core/KeylessEntityTypes/Program.cs index d3ab011688..454f1319a9 100644 --- a/samples/core/KeylessEntityTypes/Program.cs +++ b/samples/core/KeylessEntityTypes/Program.cs @@ -1,7 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.EntityFrameworkCore; @@ -70,8 +67,7 @@ private static void SetupDatabase() Url = "http://sample.com/blogs/catfish", Posts = new List { - new Post { Title = "Catfish care 101" }, - new Post { Title = "History of the catfish name" } + new Post { Title = "Catfish care 101" }, new Post { Title = "History of the catfish name" } } }); @@ -93,7 +89,8 @@ FROM Blogs b public class BloggingContext : DbContext { private static readonly ILoggerFactory _loggerFactory - = LoggerFactory.Create(builder => builder.AddConsole().AddFilter((c, l) => l == LogLevel.Information && !c.EndsWith("Connection"))); + = LoggerFactory.Create( + builder => builder.AddConsole().AddFilter((c, l) => l == LogLevel.Information && !c.EndsWith("Connection"))); public DbSet Blogs { get; set; } public DbSet Posts { get; set; } @@ -114,12 +111,13 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder - .Entity(eb => - { - eb.HasNoKey(); - eb.ToView("View_BlogPostCounts"); - eb.Property(v => v.BlogName).HasColumnName("Name"); - }); + .Entity( + eb => + { + eb.HasNoKey(); + eb.ToView("View_BlogPostCounts"); + eb.Property(v => v.BlogName).HasColumnName("Name"); + }); } #endregion } diff --git a/samples/core/Miscellaneous/Async/Async.csproj b/samples/core/Miscellaneous/Async/Async.csproj index 4bd950b09e..df73152696 100644 --- a/samples/core/Miscellaneous/Async/Async.csproj +++ b/samples/core/Miscellaneous/Async/Async.csproj @@ -1,14 +1,15 @@  + Exe net5.0 EFAsync EFAsync - - + + diff --git a/samples/core/Miscellaneous/Async/Program.cs b/samples/core/Miscellaneous/Async/Program.cs index 7e42b14f84..ccc7d0ac21 100644 --- a/samples/core/Miscellaneous/Async/Program.cs +++ b/samples/core/Miscellaneous/Async/Program.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -8,7 +6,7 @@ namespace EFAsync { public class Program { - static async Task Main(string[] args) + public static async Task Main(string[] args) { await using var context = new BloggingContext(); await context.Database.EnsureDeletedAsync(); diff --git a/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj b/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj index 9a2748ff5e..3867d010d8 100644 --- a/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj +++ b/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj @@ -1,14 +1,15 @@  + Exe net5.0 EFAsyncWithSystemInteractive EFAsyncWithSystemInteractive - - + + diff --git a/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs b/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs index c31064ea76..7034020f13 100644 --- a/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs +++ b/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -8,7 +6,7 @@ namespace EFAsync { public class Program { - static async Task Main(string[] args) + public static async Task Main(string[] args) { await using var context = new BloggingContext(); await context.Database.EnsureDeletedAsync(); diff --git a/samples/core/Miscellaneous/CachingInterception/CachingInterception.csproj b/samples/core/Miscellaneous/CachingInterception/CachingInterception.csproj index c5f2aa438b..e2f8b7144b 100644 --- a/samples/core/Miscellaneous/CachingInterception/CachingInterception.csproj +++ b/samples/core/Miscellaneous/CachingInterception/CachingInterception.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/core/Miscellaneous/Collations/Collations.csproj b/samples/core/Miscellaneous/Collations/Collations.csproj index d35b487949..903cf5b311 100644 --- a/samples/core/Miscellaneous/Collations/Collations.csproj +++ b/samples/core/Miscellaneous/Collations/Collations.csproj @@ -1,13 +1,14 @@  + Exe net5.0 EFCollations EFCollations - + diff --git a/samples/core/Miscellaneous/Collations/Program.cs b/samples/core/Miscellaneous/Collations/Program.cs index 1f46e64578..c86b9b2800 100644 --- a/samples/core/Miscellaneous/Collations/Program.cs +++ b/samples/core/Miscellaneous/Collations/Program.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using Microsoft.EntityFrameworkCore; @@ -6,7 +5,7 @@ namespace EFCollations { public class Program { - static void Main(string[] args) + public static void Main(string[] args) { using (var db = new CustomerContext()) { diff --git a/samples/core/Miscellaneous/CommandInterception/BlogsContext.cs b/samples/core/Miscellaneous/CommandInterception/BlogsContext.cs index 3c295ab44c..c410032364 100644 --- a/samples/core/Miscellaneous/CommandInterception/BlogsContext.cs +++ b/samples/core/Miscellaneous/CommandInterception/BlogsContext.cs @@ -7,10 +7,11 @@ public abstract class BlogsContext : DbContext private const string ConnectionString = @"Server=(localdb)\mssqllocaldb;Database=InterceptionTest;ConnectRetryCount=0"; protected BlogsContext() - : base(new DbContextOptionsBuilder() - .LogTo(Console.WriteLine, LogLevel.Information) - .UseSqlServer(ConnectionString) - .Options) + : base( + new DbContextOptionsBuilder() + .LogTo(Console.WriteLine, LogLevel.Information) + .UseSqlServer(ConnectionString) + .Options) { } diff --git a/samples/core/Miscellaneous/CommandInterception/CommandInterception.csproj b/samples/core/Miscellaneous/CommandInterception/CommandInterception.csproj index 4597b2a4dd..91ebbb1e46 100644 --- a/samples/core/Miscellaneous/CommandInterception/CommandInterception.csproj +++ b/samples/core/Miscellaneous/CommandInterception/CommandInterception.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/core/Miscellaneous/CommandInterception/TaggedQueryCommandInterceptor.cs b/samples/core/Miscellaneous/CommandInterception/TaggedQueryCommandInterceptor.cs index 9191b62c5b..10d2e9cd5c 100644 --- a/samples/core/Miscellaneous/CommandInterception/TaggedQueryCommandInterceptor.cs +++ b/samples/core/Miscellaneous/CommandInterception/TaggedQueryCommandInterceptor.cs @@ -36,4 +36,4 @@ private static void ManipulateCommand(DbCommand command) } } } -#endregion \ No newline at end of file +#endregion diff --git a/samples/core/Miscellaneous/CommandLine/ApplicationService.cs b/samples/core/Miscellaneous/CommandLine/ApplicationService.cs index 49bc66f220..03cada3fb8 100644 --- a/samples/core/Miscellaneous/CommandLine/ApplicationService.cs +++ b/samples/core/Miscellaneous/CommandLine/ApplicationService.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -20,6 +21,10 @@ public class Startup { public void ConfigureServices(IServiceCollection services) => services.AddDbContext(); + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + } } public class ApplicationDbContext : DbContext diff --git a/samples/core/Miscellaneous/CommandLine/CommandLine.csproj b/samples/core/Miscellaneous/CommandLine/CommandLine.csproj index 6455e436bc..3a029ff4c7 100644 --- a/samples/core/Miscellaneous/CommandLine/CommandLine.csproj +++ b/samples/core/Miscellaneous/CommandLine/CommandLine.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/samples/core/Miscellaneous/CommandLine/CustomTools.cs b/samples/core/Miscellaneous/CommandLine/CustomTools.cs index 4978aed75b..3d56143ac2 100644 --- a/samples/core/Miscellaneous/CommandLine/CustomTools.cs +++ b/samples/core/Miscellaneous/CommandLine/CustomTools.cs @@ -31,7 +31,7 @@ public static void AddMigration(string migrationName) } } - class MyDbContext : DbContext + internal class MyDbContext : DbContext { } } diff --git a/samples/core/Miscellaneous/CommandLine/DesignTimeServices.cs b/samples/core/Miscellaneous/CommandLine/DesignTimeServices.cs index efe4a6a786..9e8665f205 100644 --- a/samples/core/Miscellaneous/CommandLine/DesignTimeServices.cs +++ b/samples/core/Miscellaneous/CommandLine/DesignTimeServices.cs @@ -3,14 +3,14 @@ using Microsoft.Extensions.DependencyInjection; #region DesignTimeServices -class MyDesignTimeServices : IDesignTimeServices +internal class MyDesignTimeServices : IDesignTimeServices { public void ConfigureDesignTimeServices(IServiceCollection services) => services.AddSingleton(); } #endregion -class MyMigrationsCodeGenerator : CSharpMigrationsGenerator +internal class MyMigrationsCodeGenerator : CSharpMigrationsGenerator { public MyMigrationsCodeGenerator( MigrationsCodeGeneratorDependencies dependencies, diff --git a/samples/core/Miscellaneous/ConfiguringDbContext/AdditionalProviderConfiguration/ApplicationDbContext.cs b/samples/core/Miscellaneous/ConfiguringDbContext/AdditionalProviderConfiguration/ApplicationDbContext.cs index 04b9db563a..430d096a2f 100644 --- a/samples/core/Miscellaneous/ConfiguringDbContext/AdditionalProviderConfiguration/ApplicationDbContext.cs +++ b/samples/core/Miscellaneous/ConfiguringDbContext/AdditionalProviderConfiguration/ApplicationDbContext.cs @@ -10,10 +10,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) optionsBuilder .UseSqlServer( @"Server=(localdb)\mssqllocaldb;Database=Test", - providerOptions => - { - providerOptions.EnableRetryOnFailure(); - }); + providerOptions => { providerOptions.EnableRetryOnFailure(); }); } } #endregion diff --git a/samples/core/Miscellaneous/ConfiguringDbContext/InheritDbContext/ApplicationDbContext.cs b/samples/core/Miscellaneous/ConfiguringDbContext/InheritDbContext/ApplicationDbContext.cs index fb55dea21d..89d821a0ae 100644 --- a/samples/core/Miscellaneous/ConfiguringDbContext/InheritDbContext/ApplicationDbContext.cs +++ b/samples/core/Miscellaneous/ConfiguringDbContext/InheritDbContext/ApplicationDbContext.cs @@ -55,4 +55,3 @@ protected ApplicationDbContext(DbContextOptions contextOptions) } #endregion } - diff --git a/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/FactoryServicesExample.cs b/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/FactoryServicesExample.cs index 072fbf7eee..2097b15dbd 100644 --- a/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/FactoryServicesExample.cs +++ b/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/FactoryServicesExample.cs @@ -9,8 +9,9 @@ public class FactoryServicesExample #region ConfigureServices public void ConfigureServices(IServiceCollection services) { - services.AddDbContextFactory(options => - options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test")); + services.AddDbContextFactory( + options => + options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test")); } #endregion } diff --git a/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/MyController.cs b/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/MyController.cs index 098cd70335..e0042ba6e1 100644 --- a/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/MyController.cs +++ b/samples/core/Miscellaneous/ConfiguringDbContext/WithContextFactory/MyController.cs @@ -1,4 +1,3 @@ - using Microsoft.EntityFrameworkCore; using WebApp; diff --git a/samples/core/Miscellaneous/ConnectionInterception/ConnectionInterception.csproj b/samples/core/Miscellaneous/ConnectionInterception/ConnectionInterception.csproj index 2a910cd725..918249b0ff 100644 --- a/samples/core/Miscellaneous/ConnectionInterception/ConnectionInterception.csproj +++ b/samples/core/Miscellaneous/ConnectionInterception/ConnectionInterception.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Miscellaneous/ConnectionResiliency/ConnectionResiliency.csproj b/samples/core/Miscellaneous/ConnectionResiliency/ConnectionResiliency.csproj index ddf89b0923..7b41b2b537 100644 --- a/samples/core/Miscellaneous/ConnectionResiliency/ConnectionResiliency.csproj +++ b/samples/core/Miscellaneous/ConnectionResiliency/ConnectionResiliency.csproj @@ -1,14 +1,15 @@  + Exe net5.0 EFConnectionResiliency EFConnectionResiliency - - + + diff --git a/samples/core/Miscellaneous/ConnectionResiliency/Program.cs b/samples/core/Miscellaneous/ConnectionResiliency/Program.cs index 9845d5b1e2..80e893dc5c 100644 --- a/samples/core/Miscellaneous/ConnectionResiliency/Program.cs +++ b/samples/core/Miscellaneous/ConnectionResiliency/Program.cs @@ -7,7 +7,7 @@ namespace EFConnectionResiliency { public class Program { - static void Main(string[] args) + public static void Main(string[] args) { using (var db = new BloggingContext()) { @@ -31,22 +31,23 @@ private static void ExecuteWithManualTransaction() { var strategy = db.Database.CreateExecutionStrategy(); - strategy.Execute(() => - { - using (var context = new BloggingContext()) + strategy.Execute( + () => { - using (var transaction = context.Database.BeginTransaction()) + using (var context = new BloggingContext()) { - context.Blogs.Add(new Blog {Url = "http://blogs.msdn.com/dotnet"}); - context.SaveChanges(); + using (var transaction = context.Database.BeginTransaction()) + { + context.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/dotnet" }); + context.SaveChanges(); - context.Blogs.Add(new Blog {Url = "http://blogs.msdn.com/visualstudio"}); - context.SaveChanges(); + context.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/visualstudio" }); + context.SaveChanges(); - transaction.Commit(); + transaction.Commit(); + } } - } - }); + }); } #endregion } @@ -60,21 +61,22 @@ private static void ExecuteWithManualAmbientTransaction() var strategy = context1.Database.CreateExecutionStrategy(); - strategy.Execute(() => - { - using (var context2 = new BloggingContext()) + strategy.Execute( + () => { - using (var transaction = new TransactionScope()) + using (var context2 = new BloggingContext()) { - context2.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/dotnet" }); - context2.SaveChanges(); + using (var transaction = new TransactionScope()) + { + context2.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/dotnet" }); + context2.SaveChanges(); - context1.SaveChanges(); + context1.SaveChanges(); - transaction.Complete(); + transaction.Complete(); + } } - } - }); + }); } #endregion } @@ -86,14 +88,12 @@ private static void ExecuteInTransactionWithVerification() { var strategy = db.Database.CreateExecutionStrategy(); - var blogToAdd = new Blog {Url = "http://blogs.msdn.com/dotnet"}; + var blogToAdd = new Blog { Url = "http://blogs.msdn.com/dotnet" }; db.Blogs.Add(blogToAdd); - strategy.ExecuteInTransaction(db, - operation: context => - { - context.SaveChanges(acceptAllChangesOnSuccess: false); - }, + strategy.ExecuteInTransaction( + db, + operation: context => { context.SaveChanges(acceptAllChangesOnSuccess: false); }, verifySucceeded: context => context.Blogs.AsNoTracking().Any(b => b.BlogId == blogToAdd.BlogId)); db.ChangeTracker.AcceptAllChanges(); @@ -110,14 +110,12 @@ private static void ExecuteInTransactionWithTracking() db.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/dotnet" }); - var transaction = new TransactionRow {Id = Guid.NewGuid()}; + var transaction = new TransactionRow { Id = Guid.NewGuid() }; db.Transactions.Add(transaction); - strategy.ExecuteInTransaction(db, - operation: context => - { - context.SaveChanges(acceptAllChangesOnSuccess: false); - }, + strategy.ExecuteInTransaction( + db, + operation: context => { context.SaveChanges(acceptAllChangesOnSuccess: false); }, verifySucceeded: context => context.Transactions.AsNoTracking().Any(t => t.Id == transaction.Id)); db.ChangeTracker.AcceptAllChanges(); diff --git a/samples/core/Miscellaneous/DiagnosticListeners/DiagnosticListeners.csproj b/samples/core/Miscellaneous/DiagnosticListeners/DiagnosticListeners.csproj index c5f2aa438b..e2f8b7144b 100644 --- a/samples/core/Miscellaneous/DiagnosticListeners/DiagnosticListeners.csproj +++ b/samples/core/Miscellaneous/DiagnosticListeners/DiagnosticListeners.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/core/Miscellaneous/DiagnosticListeners/Program.cs b/samples/core/Miscellaneous/DiagnosticListeners/Program.cs index 8fc8f022b9..1938fd312b 100644 --- a/samples/core/Miscellaneous/DiagnosticListeners/Program.cs +++ b/samples/core/Miscellaneous/DiagnosticListeners/Program.cs @@ -65,15 +65,7 @@ public static void Main() context.Database.EnsureCreated(); context.Add( - new Blog - { - Name = "EF Blog", - Posts = - { - new Post { Title = "EF Core 3.1!" }, - new Post { Title = "EF Core 5.0!" } - } - }); + new Blog { Name = "EF Blog", Posts = { new Post { Title = "EF Core 3.1!" }, new Post { Title = "EF Core 5.0!" } } }); context.SaveChanges(); } diff --git a/samples/core/Miscellaneous/Events/Events.csproj b/samples/core/Miscellaneous/Events/Events.csproj index c5f2aa438b..e2f8b7144b 100644 --- a/samples/core/Miscellaneous/Events/Events.csproj +++ b/samples/core/Miscellaneous/Events/Events.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/core/Miscellaneous/Events/Program.cs b/samples/core/Miscellaneous/Events/Program.cs index 17dc064fc6..5cfb176e43 100644 --- a/samples/core/Miscellaneous/Events/Program.cs +++ b/samples/core/Miscellaneous/Events/Program.cs @@ -20,11 +20,7 @@ public static void Main() { Id = 1, Name = "EF Blog", - Posts = - { - new Post { Id = 1, Title = "EF Core 3.1!" }, - new Post { Id = 2, Title = "EF Core 5.0!" } - } + Posts = { new Post { Id = 1, Title = "EF Core 3.1!" }, new Post { Id = 2, Title = "EF Core 5.0!" } } }); context.SaveChanges(); @@ -35,7 +31,7 @@ public static void Main() var blog = context.Blogs.Include(e => e.Posts).Single(); blog.Name = "EF Core Blog"; - context.Remove(blog.Posts.First()); + context.Remove((object)blog.Posts.First()); blog.Posts.Add(new Post { Id = 3, Title = "EF Core 6.0!" }); context.SaveChanges(); diff --git a/samples/core/Miscellaneous/Logging/Logging/BloggingContext.cs b/samples/core/Miscellaneous/Logging/Logging/BloggingContext.cs index ab6f667ee4..8ab5f2f44c 100644 --- a/samples/core/Miscellaneous/Logging/Logging/BloggingContext.cs +++ b/samples/core/Miscellaneous/Logging/Logging/BloggingContext.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; @@ -43,9 +42,10 @@ public class ChangeLogLevelContext : BloggingContext #region ChangeLogLevel protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder - .ConfigureWarnings(b => b.Log( - (RelationalEventId.ConnectionOpened, LogLevel.Information), - (RelationalEventId.ConnectionClosed, LogLevel.Information))); + .ConfigureWarnings( + b => b.Log( + (RelationalEventId.ConnectionOpened, LogLevel.Information), + (RelationalEventId.ConnectionClosed, LogLevel.Information))); #endregion } @@ -66,5 +66,4 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) .ConfigureWarnings(b => b.Throw(RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning)); #endregion } - } diff --git a/samples/core/Miscellaneous/Logging/Logging/BloggingContextWithFiltering.cs b/samples/core/Miscellaneous/Logging/Logging/BloggingContextWithFiltering.cs index 2b75131512..4026525fa0 100644 --- a/samples/core/Miscellaneous/Logging/Logging/BloggingContextWithFiltering.cs +++ b/samples/core/Miscellaneous/Logging/Logging/BloggingContextWithFiltering.cs @@ -7,12 +7,14 @@ public class BloggingContextWithFiltering : DbContext { #region DefineLoggerFactory public static readonly ILoggerFactory MyLoggerFactory - = LoggerFactory.Create(builder => + = LoggerFactory.Create( + builder => { builder - .AddFilter((category, level) => - category == DbLoggerCategory.Database.Command.Name - && level == LogLevel.Information) + .AddFilter( + (category, level) => + category == DbLoggerCategory.Database.Command.Name + && level == LogLevel.Information) .AddConsole(); }); #endregion diff --git a/samples/core/Miscellaneous/Logging/Logging/Logging.csproj b/samples/core/Miscellaneous/Logging/Logging/Logging.csproj index 6b89f165f3..18dff649ef 100644 --- a/samples/core/Miscellaneous/Logging/Logging/Logging.csproj +++ b/samples/core/Miscellaneous/Logging/Logging/Logging.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Miscellaneous/Logging/SimpleLogging/Program.cs b/samples/core/Miscellaneous/Logging/SimpleLogging/Program.cs index 96f25fb3f4..24b066adc0 100755 --- a/samples/core/Miscellaneous/Logging/SimpleLogging/Program.cs +++ b/samples/core/Miscellaneous/Logging/SimpleLogging/Program.cs @@ -210,9 +210,10 @@ public class ChangeLogLevelContext : BlogsContext #region ChangeLogLevel protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder - .ConfigureWarnings(b => b.Log( - (RelationalEventId.ConnectionOpened, LogLevel.Information), - (RelationalEventId.ConnectionClosed, LogLevel.Information))) + .ConfigureWarnings( + b => b.Log( + (RelationalEventId.ConnectionOpened, LogLevel.Information), + (RelationalEventId.ConnectionClosed, LogLevel.Information))) .LogTo(Console.WriteLine, LogLevel.Information); #endregion } diff --git a/samples/core/Miscellaneous/Logging/SimpleLogging/SimpleLogging.csproj b/samples/core/Miscellaneous/Logging/SimpleLogging/SimpleLogging.csproj index 39c058216b..c1ec7b517f 100755 --- a/samples/core/Miscellaneous/Logging/SimpleLogging/SimpleLogging.csproj +++ b/samples/core/Miscellaneous/Logging/SimpleLogging/SimpleLogging.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/Miscellaneous/NullableReferenceTypes/Customer.cs b/samples/core/Miscellaneous/NullableReferenceTypes/Customer.cs index 9a375d5b96..3263e4c116 100644 --- a/samples/core/Miscellaneous/NullableReferenceTypes/Customer.cs +++ b/samples/core/Miscellaneous/NullableReferenceTypes/Customer.cs @@ -4,9 +4,9 @@ public class Customer { public int Id { get; set; } - public string FirstName { get; set; } // Required by convention - public string LastName { get; set; } // Required by convention - public string? MiddleName { get; set; } // Optional by convention + public string FirstName { get; set; } // Required by convention + public string LastName { get; set; } // Required by convention + public string? MiddleName { get; set; } // Optional by convention // Note the following use of constructor binding, which avoids compiled warnings // for uninitialized non-nullable properties. diff --git a/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithWarning.cs b/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithWarning.cs index 6c07448f48..9a757d2fb7 100644 --- a/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithWarning.cs +++ b/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithWarning.cs @@ -6,6 +6,7 @@ namespace NullableReferenceTypes public class CustomerWithWarning { public int Id { get; set; } + // Generates CS8618, uninitialized non-nullable property: public string Name { get; set; } } diff --git a/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithoutNullableReferenceTypes.cs b/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithoutNullableReferenceTypes.cs index 9c013381b7..61f5578f4b 100644 --- a/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithoutNullableReferenceTypes.cs +++ b/samples/core/Miscellaneous/NullableReferenceTypes/CustomerWithoutNullableReferenceTypes.cs @@ -8,11 +8,14 @@ namespace NullableReferenceTypes public class CustomerWithoutNullableReferenceTypes { public int Id { get; set; } - [Required] // Data annotations needed to configure as required + + [Required] // Data annotations needed to configure as required public string FirstName { get; set; } + [Required] - public string LastName { get; set; } // Data annotations needed to configure as required - public string MiddleName { get; set; } // Optional by convention + public string LastName { get; set; } // Data annotations needed to configure as required + + public string MiddleName { get; set; } // Optional by convention } #endregion } diff --git a/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypes.csproj b/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypes.csproj index ba4304df0e..e6a17c3651 100644 --- a/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypes.csproj +++ b/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypes.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypesContext.cs b/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypesContext.cs index 880dd015fd..d38a0e7461 100644 --- a/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypesContext.cs +++ b/samples/core/Miscellaneous/NullableReferenceTypes/NullableReferenceTypesContext.cs @@ -10,7 +10,8 @@ public class NullableReferenceTypesContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder - .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFNullableReferenceTypes;Trusted_Connection=True;ConnectRetryCount=0"); + .UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFNullableReferenceTypes;Trusted_Connection=True;ConnectRetryCount=0"); } #endregion } diff --git a/samples/core/Miscellaneous/NullableReferenceTypes/Program.cs b/samples/core/Miscellaneous/NullableReferenceTypes/Program.cs index 33ebef078e..56b5d24308 100644 --- a/samples/core/Miscellaneous/NullableReferenceTypes/Program.cs +++ b/samples/core/Miscellaneous/NullableReferenceTypes/Program.cs @@ -6,7 +6,7 @@ namespace NullableReferenceTypes { public static class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new NullableReferenceTypesContext()) { @@ -15,15 +15,16 @@ static void Main(string[] args) context.Add(new Customer("John", "Doe")); - context.Add(new Order - { - ShippingAddress = new Address("London", "Downing"), - Product = new Product("Cooking stove"), - OptionalInfo = new OptionalOrderInfo("Some additional info") + context.Add( + new Order { - ExtraAdditionalInfo = new ExtraOptionalOrderInfo("Some extra additional info") - } - }); + ShippingAddress = new Address("London", "Downing"), + Product = new Product("Cooking stove"), + OptionalInfo = new OptionalOrderInfo("Some additional info") + { + ExtraAdditionalInfo = new ExtraOptionalOrderInfo("Some extra additional info") + } + }); context.SaveChanges(); } @@ -35,7 +36,7 @@ static void Main(string[] args) var order = context.Orders .Include(o => o.OptionalInfo!) - .ThenInclude(op => op.ExtraAdditionalInfo) + .ThenInclude(op => op.ExtraAdditionalInfo) .Single(); // The following would be a programming bug: we forgot to include ShippingAddress above. It would throw InvalidOperationException. diff --git a/samples/core/Miscellaneous/SaveChangesInterception/AuditContext.cs b/samples/core/Miscellaneous/SaveChangesInterception/AuditContext.cs index d068d31549..aef608ba1d 100644 --- a/samples/core/Miscellaneous/SaveChangesInterception/AuditContext.cs +++ b/samples/core/Miscellaneous/SaveChangesInterception/AuditContext.cs @@ -38,4 +38,4 @@ public class EntityAudit public SaveChangesAudit SaveChangesAudit { get; set; } } -#endregion \ No newline at end of file +#endregion diff --git a/samples/core/Miscellaneous/SaveChangesInterception/AuditingInterceptor.cs b/samples/core/Miscellaneous/SaveChangesInterception/AuditingInterceptor.cs index 2088260fa1..c5f20bb174 100644 --- a/samples/core/Miscellaneous/SaveChangesInterception/AuditingInterceptor.cs +++ b/samples/core/Miscellaneous/SaveChangesInterception/AuditingInterceptor.cs @@ -16,7 +16,7 @@ public AuditingInterceptor(string connectionString) _connectionString = connectionString; } -#region SavingChanges + #region SavingChanges public async ValueTask> SavingChangesAsync( DbContextEventData eventData, InterceptionResult result, @@ -47,9 +47,9 @@ public InterceptionResult SavingChanges( return result; } -#endregion + #endregion -#region SavedChanges + #region SavedChanges public int SavedChanges(SaveChangesCompletedEventData eventData, int result) { using (var auditContext = new AuditContext(_connectionString)) @@ -80,9 +80,9 @@ public async ValueTask SavedChangesAsync( return result; } -#endregion + #endregion -#region SaveChangesFailed + #region SaveChangesFailed public void SaveChangesFailed(DbContextErrorEventData eventData) { using (var auditContext = new AuditContext(_connectionString)) @@ -110,18 +110,14 @@ public async Task SaveChangesFailedAsync( await auditContext.SaveChangesAsync(cancellationToken); } } -#endregion + #endregion -#region CreateAudit + #region CreateAudit private static SaveChangesAudit CreateAudit(DbContext context) { context.ChangeTracker.DetectChanges(); - var audit = new SaveChangesAudit - { - AuditId = Guid.NewGuid(), - StartTime = DateTime.UtcNow - }; + var audit = new SaveChangesAudit { AuditId = Guid.NewGuid(), StartTime = DateTime.UtcNow }; foreach (var entry in context.ChangeTracker.Entries()) { @@ -156,5 +152,5 @@ string CreateDeletedMessage(EntityEntry entry) $"Deleting {entry.Metadata.DisplayName()} with ", (auditString, property) => auditString + $"{property.Metadata.Name}: '{property.CurrentValue}' "); } -#endregion + #endregion } diff --git a/samples/core/Miscellaneous/SaveChangesInterception/Program.cs b/samples/core/Miscellaneous/SaveChangesInterception/Program.cs index 1f086fa878..cdc019b77c 100644 --- a/samples/core/Miscellaneous/SaveChangesInterception/Program.cs +++ b/samples/core/Miscellaneous/SaveChangesInterception/Program.cs @@ -15,15 +15,7 @@ public static async Task Main() using (var context = new BlogsContext()) { context.Add( - new Blog - { - Name = "EF Blog", - Posts = - { - new Post { Title = "EF Core 3.1!" }, - new Post { Title = "EF Core 5.0!" } - } - }); + new Blog { Name = "EF Blog", Posts = { new Post { Title = "EF Core 3.1!" }, new Post { Title = "EF Core 5.0!" } } }); await context.SaveChangesAsync(); } diff --git a/samples/core/Miscellaneous/SaveChangesInterception/SaveChangesInterception.csproj b/samples/core/Miscellaneous/SaveChangesInterception/SaveChangesInterception.csproj index c5f2aa438b..e2f8b7144b 100644 --- a/samples/core/Miscellaneous/SaveChangesInterception/SaveChangesInterception.csproj +++ b/samples/core/Miscellaneous/SaveChangesInterception/SaveChangesInterception.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/core/Miscellaneous/Testing/BusinessLogic/BlogService.cs b/samples/core/Miscellaneous/Testing/BusinessLogic/BlogService.cs index f8d8fdb3d3..00ebc6fdf7 100644 --- a/samples/core/Miscellaneous/Testing/BusinessLogic/BlogService.cs +++ b/samples/core/Miscellaneous/Testing/BusinessLogic/BlogService.cs @@ -5,7 +5,7 @@ namespace BusinessLogic { public class BlogService { - private BloggingContext _context; + private readonly BloggingContext _context; public BlogService(BloggingContext context) { diff --git a/samples/core/Miscellaneous/Testing/BusinessLogic/BloggingContext.cs b/samples/core/Miscellaneous/Testing/BusinessLogic/BloggingContext.cs index 03045301dd..e353952498 100644 --- a/samples/core/Miscellaneous/Testing/BusinessLogic/BloggingContext.cs +++ b/samples/core/Miscellaneous/Testing/BusinessLogic/BloggingContext.cs @@ -1,19 +1,21 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace BusinessLogic { public class BloggingContext : DbContext { - private Action _customizeModel; + private readonly Action _customizeModel; #region Constructors public BloggingContext() - { } + { + } public BloggingContext(DbContextOptions options) : base(options) - { } + { + } public BloggingContext(DbContextOptions options, Action customizeModel) : base(options) @@ -43,7 +45,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFProviders.InMemory;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFProviders.InMemory;Trusted_Connection=True;ConnectRetryCount=0"); } } #endregion diff --git a/samples/core/Miscellaneous/Testing/BusinessLogic/BusinessLogic.csproj b/samples/core/Miscellaneous/Testing/BusinessLogic/BusinessLogic.csproj index 88c1d919bf..b87ef655f3 100644 --- a/samples/core/Miscellaneous/Testing/BusinessLogic/BusinessLogic.csproj +++ b/samples/core/Miscellaneous/Testing/BusinessLogic/BusinessLogic.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Item.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Item.cs index 2a927efbbb..6d3efed647 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Item.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Item.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; @@ -41,4 +40,4 @@ public Tag AddTag(string label) public IReadOnlyList Tags => _tags; } #endregion -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsContext.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsContext.cs index cfa5f22009..fc5d1afca2 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsContext.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsContext.cs @@ -14,23 +14,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #region ConfigureItem modelBuilder.Entity( b => - { - b.Property("_id"); - b.HasKey("_id"); - b.Property(e => e.Name); - b.HasMany(e => e.Tags).WithOne().IsRequired(); - }); + { + b.Property("_id"); + b.HasKey("_id"); + b.Property(e => e.Name); + b.HasMany(e => e.Tags).WithOne().IsRequired(); + }); #endregion #region ConfigureTag modelBuilder.Entity( b => - { - b.Property("_id"); - b.HasKey("_id"); - b.Property(e => e.Label); - }); + { + b.Property("_id"); + b.HasKey("_id"); + b.Property(e => e.Label); + }); #endregion } } -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsWebApi.csproj b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsWebApi.csproj index 0b87485ffa..d18803298a 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsWebApi.csproj +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/ItemsWebApi.csproj @@ -6,7 +6,7 @@ - + diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Program.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Program.cs index e1a2f6f16a..9d0056522a 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Program.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Program.cs @@ -14,4 +14,4 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); } -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Startup.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Startup.cs index ab639b06b4..9a30ca233c 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Startup.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Startup.cs @@ -21,8 +21,9 @@ public void ConfigureServices(IServiceCollection services) { services.AddControllers(); - services.AddDbContext(b => b.UseSqlServer( - @"Server=(localdb)\mssqllocaldb;Database=EFTestSample;ConnectRetryCount=0")); + services.AddDbContext( + b => b.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFTestSample;ConnectRetryCount=0")); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -39,4 +40,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Tag.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Tag.cs index 0717c694e7..02084f9c68 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Tag.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/ItemsWebApi/Tag.cs @@ -18,4 +18,4 @@ private Tag(int id, string label) public int Count { get; set; } } #endregion -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTest.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTest.cs index 9e4b7a16b9..355a3ce535 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTest.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTest.cs @@ -12,7 +12,6 @@ public class SharedDatabaseTest : IClassFixture public SharedDatabaseTest(SharedDatabaseFixture fixture) => Fixture = fixture; public SharedDatabaseFixture Fixture { get; } - #endregion #region CanGetItems diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTests.csproj b/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTests.csproj index dd7daf5b29..b9327fc760 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTests.csproj +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/SharedDatabaseTests/SharedDatabaseTests.csproj @@ -5,7 +5,7 @@ - + diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/InMemoryItemsControllerTest.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/InMemoryItemsControllerTest.cs index 734e7bfa15..6ac4840eb4 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/InMemoryItemsControllerTest.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/InMemoryItemsControllerTest.cs @@ -13,4 +13,4 @@ public InMemoryItemsControllerTest() { } } -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqlServerItemsControllerTest.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqlServerItemsControllerTest.cs index f1b68ef192..3ed3166ba6 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqlServerItemsControllerTest.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqlServerItemsControllerTest.cs @@ -13,4 +13,4 @@ public SqlServerItemsControllerTest() { } } -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteInMemoryItemsControllerTest.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteInMemoryItemsControllerTest.cs index 1f28edea5b..e4ed2ea306 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteInMemoryItemsControllerTest.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteInMemoryItemsControllerTest.cs @@ -33,4 +33,4 @@ private static DbConnection CreateInMemoryDatabase() public void Dispose() => _connection.Dispose(); } #endregion -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteItemsControllerTest.cs b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteItemsControllerTest.cs index d0c3e68bc8..1376e4c2ef 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteItemsControllerTest.cs +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/SqliteItemsControllerTest.cs @@ -15,4 +15,4 @@ public SqliteItemsControllerTest() } } #endregion -} \ No newline at end of file +} diff --git a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/Tests.csproj b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/Tests.csproj index 4dfbfa2ea3..9f60efa1a7 100644 --- a/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/Tests.csproj +++ b/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/Tests.csproj @@ -5,9 +5,9 @@ - - - + + + diff --git a/samples/core/Miscellaneous/Testing/TestProject/InMemory/BlogServiceTests.cs b/samples/core/Miscellaneous/Testing/TestProject/InMemory/BlogServiceTests.cs index 3007bca7d8..75787907db 100644 --- a/samples/core/Miscellaneous/Testing/TestProject/InMemory/BlogServiceTests.cs +++ b/samples/core/Miscellaneous/Testing/TestProject/InMemory/BlogServiceTests.cs @@ -1,6 +1,6 @@ -using BusinessLogic; +using System.Linq; +using BusinessLogic; using Microsoft.EntityFrameworkCore; -using System.Linq; using Xunit; namespace EFTesting.TestProject.InMemory @@ -81,10 +81,11 @@ public void GetAllResources_returns_all_resources() } private static BloggingContext CreateContext(DbContextOptions options) - => new BloggingContext(options, (context, modelBuilder) => - { - modelBuilder.Entity() - .ToInMemoryQuery(() => context.Blogs.Select(b => new UrlResource { Url = b.Url })); - }); + => new BloggingContext( + options, (context, modelBuilder) => + { + modelBuilder.Entity() + .ToInMemoryQuery(() => context.Blogs.Select(b => new UrlResource { Url = b.Url })); + }); } } diff --git a/samples/core/Miscellaneous/Testing/TestProject/SQLite/BlogServiceTests.cs b/samples/core/Miscellaneous/Testing/TestProject/SQLite/BlogServiceTests.cs index eb6503e531..f7f2ea31b2 100644 --- a/samples/core/Miscellaneous/Testing/TestProject/SQLite/BlogServiceTests.cs +++ b/samples/core/Miscellaneous/Testing/TestProject/SQLite/BlogServiceTests.cs @@ -1,7 +1,7 @@ -using BusinessLogic; +using System.Linq; +using BusinessLogic; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; -using System.Linq; using Xunit; namespace EFTesting.TestProject.SQLite diff --git a/samples/core/Miscellaneous/Testing/TestProject/TestProject.csproj b/samples/core/Miscellaneous/Testing/TestProject/TestProject.csproj index 8d28317dff..43a678b98c 100644 --- a/samples/core/Miscellaneous/Testing/TestProject/TestProject.csproj +++ b/samples/core/Miscellaneous/Testing/TestProject/TestProject.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/core/Modeling/Conventions/AlternateKey.cs b/samples/core/Modeling/Conventions/AlternateKey.cs index 4461f2fc70..608f2a019d 100644 --- a/samples/core/Modeling/Conventions/AlternateKey.cs +++ b/samples/core/Modeling/Conventions/AlternateKey.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Conventions.AlternateKey { #region AlternateKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/Conventions/BackingField.cs b/samples/core/Modeling/Conventions/BackingField.cs index 5f9da0055c..e126373344 100644 --- a/samples/core/Modeling/Conventions/BackingField.cs +++ b/samples/core/Modeling/Conventions/BackingField.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; namespace EFModeling.Conventions.BackingField { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -11,15 +10,9 @@ class MyContext : DbContext #region Sample public class Blog { - private string _url; - public int BlogId { get; set; } - public string Url - { - get { return _url; } - set { _url = value; } - } + public string Url { get; set; } } #endregion } diff --git a/samples/core/Modeling/Conventions/Conventions.csproj b/samples/core/Modeling/Conventions/Conventions.csproj index d83e92e624..1f0cf169c4 100644 --- a/samples/core/Modeling/Conventions/Conventions.csproj +++ b/samples/core/Modeling/Conventions/Conventions.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Modeling/Conventions/EntityTypes.cs b/samples/core/Modeling/Conventions/EntityTypes.cs index 216614b8f8..2178787870 100644 --- a/samples/core/Modeling/Conventions/EntityTypes.cs +++ b/samples/core/Modeling/Conventions/EntityTypes.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Conventions.EntityTypes { #region EntityTypes - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } @@ -61,7 +61,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFModeling.EntityTypeToFunctionMapping;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFModeling.EntityTypeToFunctionMapping;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Modeling/Conventions/InheritanceDbSets.cs b/samples/core/Modeling/Conventions/InheritanceDbSets.cs index 61ae8bf406..36a46c60ca 100644 --- a/samples/core/Modeling/Conventions/InheritanceDbSets.cs +++ b/samples/core/Modeling/Conventions/InheritanceDbSets.cs @@ -2,9 +2,8 @@ namespace EFModeling.Conventions.InheritanceDbSets { - #region InheritanceDbSets - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet RssBlogs { get; set; } diff --git a/samples/core/Modeling/Conventions/KeyId.cs b/samples/core/Modeling/Conventions/KeyId.cs index fb82bbf927..769a155038 100644 --- a/samples/core/Modeling/Conventions/KeyId.cs +++ b/samples/core/Modeling/Conventions/KeyId.cs @@ -1,16 +1,15 @@ using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; namespace EFModeling.Conventions.KeyId { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } public DbSet Trucks { get; set; } } #region KeyId - class Car + internal class Car { public string Id { get; set; } @@ -18,7 +17,7 @@ class Car public string Model { get; set; } } - class Truck + internal class Truck { public string TruckId { get; set; } diff --git a/samples/core/Modeling/Conventions/Program.cs b/samples/core/Modeling/Conventions/Program.cs index 10f158b490..8c0bf8f062 100644 --- a/samples/core/Modeling/Conventions/Program.cs +++ b/samples/core/Modeling/Conventions/Program.cs @@ -1,12 +1,12 @@ -using EFModeling.Conventions.EntityTypes; +using System.Linq; +using EFModeling.Conventions.EntityTypes; using Microsoft.EntityFrameworkCore; -using System.Linq; namespace EFModeling.Conventions { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new MyContextWithFunctionMapping()) { diff --git a/samples/core/Modeling/Conventions/Relationships/Full.cs b/samples/core/Modeling/Conventions/Relationships/Full.cs index 40f0aef20b..a991aac743 100644 --- a/samples/core/Modeling/Conventions/Relationships/Full.cs +++ b/samples/core/Modeling/Conventions/Relationships/Full.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Conventions.Relationships.Full { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/Conventions/Relationships/NoForeignKey.cs b/samples/core/Modeling/Conventions/Relationships/NoForeignKey.cs index 9e6ed6090b..016a73b34b 100644 --- a/samples/core/Modeling/Conventions/Relationships/NoForeignKey.cs +++ b/samples/core/Modeling/Conventions/Relationships/NoForeignKey.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Conventions.Relationships.NoForeignKey { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/Conventions/Relationships/OneNavigation.cs b/samples/core/Modeling/Conventions/Relationships/OneNavigation.cs index 62f1f4c6dd..fc90a9598d 100644 --- a/samples/core/Modeling/Conventions/Relationships/OneNavigation.cs +++ b/samples/core/Modeling/Conventions/Relationships/OneNavigation.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Conventions.Relationships.OneNavigation { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/Conventions/Relationships/OneToOne.cs b/samples/core/Modeling/Conventions/Relationships/OneToOne.cs index 5edbc1c7a7..69fbb4d3d4 100644 --- a/samples/core/Modeling/Conventions/Relationships/OneToOne.cs +++ b/samples/core/Modeling/Conventions/Relationships/OneToOne.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; namespace EFModeling.Conventions.Relationships.OneToOne { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet BlogImages { get; set; } diff --git a/samples/core/Modeling/Conventions/ShadowForeignKey.cs b/samples/core/Modeling/Conventions/ShadowForeignKey.cs index 28b90dcd77..5828222f0f 100644 --- a/samples/core/Modeling/Conventions/ShadowForeignKey.cs +++ b/samples/core/Modeling/Conventions/ShadowForeignKey.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Conventions.ShadowForeignKey { #region Conventions - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/DataAnnotations/BackingField.cs b/samples/core/Modeling/DataAnnotations/BackingField.cs index 4cc5300ca2..daa01fcdab 100644 --- a/samples/core/Modeling/DataAnnotations/BackingField.cs +++ b/samples/core/Modeling/DataAnnotations/BackingField.cs @@ -2,7 +2,7 @@ namespace EFModeling.DataAnnotations.BackingField { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -22,7 +22,7 @@ public string Url public void SetUrl(string url) { - // put your validation code here + // put your validation code here _validatedUrl = url; } diff --git a/samples/core/Modeling/DataAnnotations/ColumnComment.cs b/samples/core/Modeling/DataAnnotations/ColumnComment.cs index b19f5f5ff4..58abacb55a 100644 --- a/samples/core/Modeling/DataAnnotations/ColumnComment.cs +++ b/samples/core/Modeling/DataAnnotations/ColumnComment.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations.Schema; namespace EFModeling.DataAnnotations.Relational.ColumnComment { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -12,6 +11,7 @@ class MyContext : DbContext public class Blog { public int BlogId { get; set; } + [Comment("The URL of the blog")] public string Url { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/ColumnDataType.cs b/samples/core/Modeling/DataAnnotations/ColumnDataType.cs index caf80ac554..c096dc93df 100644 --- a/samples/core/Modeling/DataAnnotations/ColumnDataType.cs +++ b/samples/core/Modeling/DataAnnotations/ColumnDataType.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Relational.ColumnDataType { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -12,8 +12,10 @@ class MyContext : DbContext public class Blog { public int BlogId { get; set; } + [Column(TypeName = "varchar(200)")] public string Url { get; set; } + [Column(TypeName = "decimal(5, 2)")] public decimal Rating { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/ColumnName.cs b/samples/core/Modeling/DataAnnotations/ColumnName.cs index ec5a42960f..e4b81c7c8f 100644 --- a/samples/core/Modeling/DataAnnotations/ColumnName.cs +++ b/samples/core/Modeling/DataAnnotations/ColumnName.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Relational.ColumnName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -13,6 +13,7 @@ public class Blog { [Column("blog_id")] public int BlogId { get; set; } + public string Url { get; set; } } #endregion diff --git a/samples/core/Modeling/DataAnnotations/Concurrency.cs b/samples/core/Modeling/DataAnnotations/Concurrency.cs index 6a8fcd4b93..2a4f659e79 100644 --- a/samples/core/Modeling/DataAnnotations/Concurrency.cs +++ b/samples/core/Modeling/DataAnnotations/Concurrency.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Concurrency { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet People { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/DataAnnotations.csproj b/samples/core/Modeling/DataAnnotations/DataAnnotations.csproj index ccb9087836..bca6293fde 100644 --- a/samples/core/Modeling/DataAnnotations/DataAnnotations.csproj +++ b/samples/core/Modeling/DataAnnotations/DataAnnotations.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Modeling/DataAnnotations/IgnoreProperty.cs b/samples/core/Modeling/DataAnnotations/IgnoreProperty.cs index 7a265fb8c1..2454afb6fd 100644 --- a/samples/core/Modeling/DataAnnotations/IgnoreProperty.cs +++ b/samples/core/Modeling/DataAnnotations/IgnoreProperty.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.IgnoreProperty { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/IgnoreType.cs b/samples/core/Modeling/DataAnnotations/IgnoreType.cs index e1eb0d3bd5..ddf6ba532a 100644 --- a/samples/core/Modeling/DataAnnotations/IgnoreType.cs +++ b/samples/core/Modeling/DataAnnotations/IgnoreType.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.IgnoreType { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/Index.cs b/samples/core/Modeling/DataAnnotations/Index.cs index 8dfe219cac..74923c04e2 100644 --- a/samples/core/Modeling/DataAnnotations/Index.cs +++ b/samples/core/Modeling/DataAnnotations/Index.cs @@ -2,7 +2,7 @@ namespace EFModeling.DataAnnotations.Index { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/IndexComposite.cs b/samples/core/Modeling/DataAnnotations/IndexComposite.cs index 418bc87094..7bc68fb549 100644 --- a/samples/core/Modeling/DataAnnotations/IndexComposite.cs +++ b/samples/core/Modeling/DataAnnotations/IndexComposite.cs @@ -2,7 +2,7 @@ namespace EFModeling.DataAnnotations.IndexComposite { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet People { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/IndexName.cs b/samples/core/Modeling/DataAnnotations/IndexName.cs index 9b924fe36b..c64b3ed03e 100644 --- a/samples/core/Modeling/DataAnnotations/IndexName.cs +++ b/samples/core/Modeling/DataAnnotations/IndexName.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.IndexName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/IndexUnique.cs b/samples/core/Modeling/DataAnnotations/IndexUnique.cs index 323107bf99..6400b36941 100644 --- a/samples/core/Modeling/DataAnnotations/IndexUnique.cs +++ b/samples/core/Modeling/DataAnnotations/IndexUnique.cs @@ -2,7 +2,7 @@ namespace EFModeling.DataAnnotations.IndexUnique { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/KeySingle.cs b/samples/core/Modeling/DataAnnotations/KeySingle.cs index dcb75fadac..5a96d15121 100644 --- a/samples/core/Modeling/DataAnnotations/KeySingle.cs +++ b/samples/core/Modeling/DataAnnotations/KeySingle.cs @@ -1,15 +1,15 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.KeySingle { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } } #region KeySingle - class Car + internal class Car { [Key] public string LicensePlate { get; set; } diff --git a/samples/core/Modeling/DataAnnotations/Keyless.cs b/samples/core/Modeling/DataAnnotations/Keyless.cs index cba53a0462..0e5b7a710f 100644 --- a/samples/core/Modeling/DataAnnotations/Keyless.cs +++ b/samples/core/Modeling/DataAnnotations/Keyless.cs @@ -2,7 +2,7 @@ namespace EFModeling.DataAnnotations.Keyless { - class BlogsContext : DbContext + internal class BlogsContext : DbContext { public DbSet BlogPostCounts { get; set; } } @@ -15,4 +15,4 @@ public class BlogPostsCount public int PostCount { get; set; } } #endregion -} \ No newline at end of file +} diff --git a/samples/core/Modeling/DataAnnotations/MaxLength.cs b/samples/core/Modeling/DataAnnotations/MaxLength.cs index abaeb923d0..ee8de7ccf7 100644 --- a/samples/core/Modeling/DataAnnotations/MaxLength.cs +++ b/samples/core/Modeling/DataAnnotations/MaxLength.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.MaxLength { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -12,6 +12,7 @@ class MyContext : DbContext public class Blog { public int BlogId { get; set; } + [MaxLength(500)] public string Url { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/Program.cs b/samples/core/Modeling/DataAnnotations/Program.cs index 98a7514fd1..5d27a7e9df 100644 --- a/samples/core/Modeling/DataAnnotations/Program.cs +++ b/samples/core/Modeling/DataAnnotations/Program.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EFModeling.DataAnnotations +namespace EFModeling.DataAnnotations { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { } } diff --git a/samples/core/Modeling/DataAnnotations/Relationships/ForeignKey.cs b/samples/core/Modeling/DataAnnotations/Relationships/ForeignKey.cs index 169190d2de..4874b212f6 100644 --- a/samples/core/Modeling/DataAnnotations/Relationships/ForeignKey.cs +++ b/samples/core/Modeling/DataAnnotations/Relationships/ForeignKey.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Relationships.ForeignKey { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/DataAnnotations/Relationships/InverseProperty.cs b/samples/core/Modeling/DataAnnotations/Relationships/InverseProperty.cs index 5d3ec09ba3..ea74bb7f34 100644 --- a/samples/core/Modeling/DataAnnotations/Relationships/InverseProperty.cs +++ b/samples/core/Modeling/DataAnnotations/Relationships/InverseProperty.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Relationships.InverseProperty { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Posts { get; set; } public DbSet Users { get; set; } diff --git a/samples/core/Modeling/DataAnnotations/Required.cs b/samples/core/Modeling/DataAnnotations/Required.cs index 581de0d061..bc142df6dd 100644 --- a/samples/core/Modeling/DataAnnotations/Required.cs +++ b/samples/core/Modeling/DataAnnotations/Required.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Required { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -12,6 +12,7 @@ class MyContext : DbContext public class Blog { public int BlogId { get; set; } + [Required] public string Url { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/TableComment.cs b/samples/core/Modeling/DataAnnotations/TableComment.cs index cbff754e3a..4281938313 100644 --- a/samples/core/Modeling/DataAnnotations/TableComment.cs +++ b/samples/core/Modeling/DataAnnotations/TableComment.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations.Schema; namespace EFModeling.DataAnnotations.Relational.TableComment { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/TableName.cs b/samples/core/Modeling/DataAnnotations/TableName.cs index c462028dfb..9b8ecc445e 100644 --- a/samples/core/Modeling/DataAnnotations/TableName.cs +++ b/samples/core/Modeling/DataAnnotations/TableName.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Relational.TableName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/TableNameAndSchema.cs b/samples/core/Modeling/DataAnnotations/TableNameAndSchema.cs index a4faf123d1..dd8a201be4 100644 --- a/samples/core/Modeling/DataAnnotations/TableNameAndSchema.cs +++ b/samples/core/Modeling/DataAnnotations/TableNameAndSchema.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Relational.TableNameAndSchema { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/Timestamp.cs b/samples/core/Modeling/DataAnnotations/Timestamp.cs index c9ca6d2ffb..18bc37db35 100644 --- a/samples/core/Modeling/DataAnnotations/Timestamp.cs +++ b/samples/core/Modeling/DataAnnotations/Timestamp.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.Timestamp { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/ValueGeneratedNever.cs b/samples/core/Modeling/DataAnnotations/ValueGeneratedNever.cs index c0b9d023ba..8f044bdeba 100644 --- a/samples/core/Modeling/DataAnnotations/ValueGeneratedNever.cs +++ b/samples/core/Modeling/DataAnnotations/ValueGeneratedNever.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.ValueGeneratedNever { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -13,6 +13,7 @@ public class Blog { [DatabaseGenerated(DatabaseGeneratedOption.None)] public int BlogId { get; set; } + public string Url { get; set; } } #endregion diff --git a/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAdd.cs b/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAdd.cs index 8f3b958e2b..f2c0ca5f4b 100644 --- a/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAdd.cs +++ b/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAdd.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.ValueGeneratedOnAdd { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -14,6 +14,7 @@ public class Blog { public int BlogId { get; set; } public string Url { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public DateTime Inserted { get; set; } } diff --git a/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAddOrUpdate.cs b/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAddOrUpdate.cs index 8bcc863d9a..c4a94405b1 100644 --- a/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAddOrUpdate.cs +++ b/samples/core/Modeling/DataAnnotations/ValueGeneratedOnAddOrUpdate.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; namespace EFModeling.DataAnnotations.ValueGeneratedOnAddOrUpdate { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } } @@ -14,6 +14,7 @@ public class Blog { public int BlogId { get; set; } public string Url { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public DateTime LastUpdated { get; set; } } diff --git a/samples/core/Modeling/DataSeeding/DataSeeding.csproj b/samples/core/Modeling/DataSeeding/DataSeeding.csproj index eaa0b883dd..1d914c0da9 100644 --- a/samples/core/Modeling/DataSeeding/DataSeeding.csproj +++ b/samples/core/Modeling/DataSeeding/DataSeeding.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Modeling/DataSeeding/DataSeedingContext.cs b/samples/core/Modeling/DataSeeding/DataSeedingContext.cs index 8d24239965..ddccfb49bd 100644 --- a/samples/core/Modeling/DataSeeding/DataSeedingContext.cs +++ b/samples/core/Modeling/DataSeeding/DataSeedingContext.cs @@ -13,25 +13,23 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(entity => - { - entity.Property(e => e.Url).IsRequired(); - }); + modelBuilder.Entity(entity => { entity.Property(e => e.Url).IsRequired(); }); #region BlogSeed - modelBuilder.Entity().HasData(new Blog {BlogId = 1, Url = "http://sample.com"}); + modelBuilder.Entity().HasData(new Blog { BlogId = 1, Url = "http://sample.com" }); #endregion - modelBuilder.Entity(entity => - { - entity.HasOne(d => d.Blog) - .WithMany(p => p.Posts) - .HasForeignKey("BlogId"); - }); + modelBuilder.Entity( + entity => + { + entity.HasOne(d => d.Blog) + .WithMany(p => p.Posts) + .HasForeignKey("BlogId"); + }); #region PostSeed modelBuilder.Entity().HasData( - new Post() { BlogId = 1, PostId = 1, Title = "First post", Content = "Test 1" }); + new Post { BlogId = 1, PostId = 1, Title = "First post", Content = "Test 1" }); #endregion #region AnonymousPostSeed diff --git a/samples/core/Modeling/DataSeeding/Migrations/20181102235626_Initial.cs b/samples/core/Modeling/DataSeeding/Migrations/20181102235626_Initial.cs index 3bdf6a3f99..84129ea41f 100644 --- a/samples/core/Modeling/DataSeeding/Migrations/20181102235626_Initial.cs +++ b/samples/core/Modeling/DataSeeding/Migrations/20181102235626_Initial.cs @@ -15,10 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), Url = table.Column(nullable: false) }, - constraints: table => - { - table.PrimaryKey("PK_Blogs", x => x.BlogId); - }); + constraints: table => { table.PrimaryKey("PK_Blogs", x => x.BlogId); }); migrationBuilder.CreateTable( name: "Posts", diff --git a/samples/core/Modeling/DataSeeding/Migrations/DataSeedingContextModelSnapshot.cs b/samples/core/Modeling/DataSeeding/Migrations/DataSeedingContextModelSnapshot.cs index 82cad2afbb..6d308f8f73 100644 --- a/samples/core/Modeling/DataSeeding/Migrations/DataSeedingContextModelSnapshot.cs +++ b/samples/core/Modeling/DataSeeding/Migrations/DataSeedingContextModelSnapshot.cs @@ -1,15 +1,11 @@ -// -using System; -using EFModeling.DataSeeding; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EFModeling.DataSeeding.Migrations { [DbContext(typeof(DataSeedingContext))] - partial class DataSeedingContextModelSnapshot : ModelSnapshot + internal class DataSeedingContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -19,7 +15,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("EFModeling.DataSeeding.Blog", b => + modelBuilder.Entity( + "EFModeling.DataSeeding.Blog", b => { b.Property("BlogId") .ValueGeneratedOnAdd() @@ -37,7 +34,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) ); }); - modelBuilder.Entity("EFModeling.DataSeeding.Post", b => + modelBuilder.Entity( + "EFModeling.DataSeeding.Post", b => { b.Property("PostId") .ValueGeneratedOnAdd() @@ -61,14 +59,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) ); }); - modelBuilder.Entity("EFModeling.DataSeeding.Post", b => + modelBuilder.Entity( + "EFModeling.DataSeeding.Post", b => { b.HasOne("EFModeling.DataSeeding.Blog", "Blog") .WithMany("Posts") .HasForeignKey("BlogId") .OnDelete(DeleteBehavior.Cascade); - b.OwnsOne("EFModeling.DataSeeding.Name", "AuthorName", b1 => + b.OwnsOne( + "EFModeling.DataSeeding.Name", "AuthorName", b1 => { b1.Property("PostId") .ValueGeneratedOnAdd() diff --git a/samples/core/Modeling/DataSeeding/Program.cs b/samples/core/Modeling/DataSeeding/Program.cs index 4f1a6246dc..5b0f68ebc3 100644 --- a/samples/core/Modeling/DataSeeding/Program.cs +++ b/samples/core/Modeling/DataSeeding/Program.cs @@ -4,9 +4,9 @@ namespace EFModeling.DataSeeding { - static class Program + internal static class Program { - static void Main(string[] args) + private static void Main(string[] args) { #region CustomSeeding using (var context = new DataSeedingContext()) @@ -18,6 +18,7 @@ static void Main(string[] args) { context.Blogs.Add(new Blog { Url = "http://test.com" }); } + context.SaveChanges(); } #endregion diff --git a/samples/core/Modeling/DynamicModel/DynamicModel.csproj b/samples/core/Modeling/DynamicModel/DynamicModel.csproj index d153cb4567..ce933d1cc2 100644 --- a/samples/core/Modeling/DynamicModel/DynamicModel.csproj +++ b/samples/core/Modeling/DynamicModel/DynamicModel.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Modeling/DynamicModel/Program.cs b/samples/core/Modeling/DynamicModel/Program.cs index 642a591d95..a1ab4c00d9 100644 --- a/samples/core/Modeling/DynamicModel/Program.cs +++ b/samples/core/Modeling/DynamicModel/Program.cs @@ -5,7 +5,7 @@ namespace EFModeling.DynamicModel { public class Program { - static void Main() + private static void Main() { // Note that because this sample uses InMemory as its provider, each model gets it's own separate store. diff --git a/samples/core/Modeling/FluentAPI/AlternateKeyComposite.cs b/samples/core/Modeling/FluentAPI/AlternateKeyComposite.cs index 1cb2abcfe3..f47ab09747 100644 --- a/samples/core/Modeling/FluentAPI/AlternateKeyComposite.cs +++ b/samples/core/Modeling/FluentAPI/AlternateKeyComposite.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.AlternateKeyComposite { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } @@ -15,7 +15,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #endregion } - class Car + internal class Car { public int CarId { get; set; } public string State { get; set; } diff --git a/samples/core/Modeling/FluentAPI/AlternateKeyName.cs b/samples/core/Modeling/FluentAPI/AlternateKeyName.cs index c34e9f94d8..1f3c8af1a0 100644 --- a/samples/core/Modeling/FluentAPI/AlternateKeyName.cs +++ b/samples/core/Modeling/FluentAPI/AlternateKeyName.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.AlternateKeyName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } @@ -16,7 +16,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #endregion } - class Car + internal class Car { public int CarId { get; set; } public string LicensePlate { get; set; } diff --git a/samples/core/Modeling/FluentAPI/AlternateKeySingle.cs b/samples/core/Modeling/FluentAPI/AlternateKeySingle.cs index 03c7efab3e..fbce33f430 100644 --- a/samples/core/Modeling/FluentAPI/AlternateKeySingle.cs +++ b/samples/core/Modeling/FluentAPI/AlternateKeySingle.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.AlternateKeySingle { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } @@ -15,7 +15,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #endregion } - class Car + internal class Car { public int CarId { get; set; } public string LicensePlate { get; set; } diff --git a/samples/core/Modeling/FluentAPI/BackingField.cs b/samples/core/Modeling/FluentAPI/BackingField.cs index 9ec82f3a89..f65ea77e9b 100644 --- a/samples/core/Modeling/FluentAPI/BackingField.cs +++ b/samples/core/Modeling/FluentAPI/BackingField.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Net.Http; +using System.Net.Http; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.BackingField { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } @@ -19,14 +19,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) public class Blog { - private string _validatedUrl; - public int BlogId { get; set; } - public string Url - { - get { return _validatedUrl; } - } + public string Url { get; private set; } public void SetUrl(string url) { @@ -36,7 +31,7 @@ public void SetUrl(string url) response.EnsureSuccessStatusCode(); } - _validatedUrl = url; + Url = url; } } } diff --git a/samples/core/Modeling/FluentAPI/BackingFieldAccessMode.cs b/samples/core/Modeling/FluentAPI/BackingFieldAccessMode.cs index ee814d0ecc..c1b70fa3a0 100644 --- a/samples/core/Modeling/FluentAPI/BackingFieldAccessMode.cs +++ b/samples/core/Modeling/FluentAPI/BackingFieldAccessMode.cs @@ -1,10 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using System.Net.Http; +using System.Net.Http; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.BackingFieldAccessMode { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } @@ -21,14 +20,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) public class Blog { - private string _validatedUrl; - public int BlogId { get; set; } - public string Url - { - get { return _validatedUrl; } - } + public string Url { get; private set; } public void SetUrl(string url) { @@ -38,7 +32,7 @@ public void SetUrl(string url) response.EnsureSuccessStatusCode(); } - _validatedUrl = url; + Url = url; } } } diff --git a/samples/core/Modeling/FluentAPI/BackingFieldNoProperty.cs b/samples/core/Modeling/FluentAPI/BackingFieldNoProperty.cs index 348e00b77d..b83dada3e3 100644 --- a/samples/core/Modeling/FluentAPI/BackingFieldNoProperty.cs +++ b/samples/core/Modeling/FluentAPI/BackingFieldNoProperty.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Net.Http; +using System.Net.Http; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.BackingFieldNoProperty { #region Sample - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ColumnComment.cs b/samples/core/Modeling/FluentAPI/ColumnComment.cs index bd12f32cc3..9154655abc 100644 --- a/samples/core/Modeling/FluentAPI/ColumnComment.cs +++ b/samples/core/Modeling/FluentAPI/ColumnComment.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System; namespace EFModeling.FluentAPI.ColumnComment { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ColumnDataType.cs b/samples/core/Modeling/FluentAPI/ColumnDataType.cs index ec88df54d9..122825ea0c 100644 --- a/samples/core/Modeling/FluentAPI/ColumnDataType.cs +++ b/samples/core/Modeling/FluentAPI/ColumnDataType.cs @@ -2,18 +2,19 @@ namespace EFModeling.FluentAPI.Relational.DataType { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } #region ColumnDataType protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(eb => - { - eb.Property(b => b.Url).HasColumnType("varchar(200)"); - eb.Property(b => b.Rating).HasColumnType("decimal(5, 2)"); - }); + modelBuilder.Entity( + eb => + { + eb.Property(b => b.Url).HasColumnType("varchar(200)"); + eb.Property(b => b.Rating).HasColumnType("decimal(5, 2)"); + }); } #endregion } diff --git a/samples/core/Modeling/FluentAPI/ColumnName.cs b/samples/core/Modeling/FluentAPI/ColumnName.cs index f7e685f5af..94e5693edb 100644 --- a/samples/core/Modeling/FluentAPI/ColumnName.cs +++ b/samples/core/Modeling/FluentAPI/ColumnName.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.ColumnName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ComputedColumn.cs b/samples/core/Modeling/FluentAPI/ComputedColumn.cs index 4e0a5c483e..ae477512f2 100644 --- a/samples/core/Modeling/FluentAPI/ComputedColumn.cs +++ b/samples/core/Modeling/FluentAPI/ComputedColumn.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.ComputedColumn { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet People { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Concurrency.cs b/samples/core/Modeling/FluentAPI/Concurrency.cs index e0c2320cd7..40877e69d4 100644 --- a/samples/core/Modeling/FluentAPI/Concurrency.cs +++ b/samples/core/Modeling/FluentAPI/Concurrency.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Concurrency { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet People { get; set; } diff --git a/samples/core/Modeling/FluentAPI/DefaultSchema.cs b/samples/core/Modeling/FluentAPI/DefaultSchema.cs index d61dcfafa3..d0ba6665f4 100644 --- a/samples/core/Modeling/FluentAPI/DefaultSchema.cs +++ b/samples/core/Modeling/FluentAPI/DefaultSchema.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.DefaultSchema { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/DefaultValue.cs b/samples/core/Modeling/FluentAPI/DefaultValue.cs index 0cc43cff9b..9940b92f96 100644 --- a/samples/core/Modeling/FluentAPI/DefaultValue.cs +++ b/samples/core/Modeling/FluentAPI/DefaultValue.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.DefaultValue { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/DefaultValueSql.cs b/samples/core/Modeling/FluentAPI/DefaultValueSql.cs index 5ab08d74e2..13fb2eba60 100644 --- a/samples/core/Modeling/FluentAPI/DefaultValueSql.cs +++ b/samples/core/Modeling/FluentAPI/DefaultValueSql.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relational.DefaultValueSql { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/EntityTypeConfiguration.cs b/samples/core/Modeling/FluentAPI/EntityTypeConfiguration.cs index 5c9204500a..03e0a55f08 100644 --- a/samples/core/Modeling/FluentAPI/EntityTypeConfiguration.cs +++ b/samples/core/Modeling/FluentAPI/EntityTypeConfiguration.cs @@ -3,7 +3,7 @@ namespace EFModeling.FluentAPI.EntityTypeConfiguration { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/FluentAPI.csproj b/samples/core/Modeling/FluentAPI/FluentAPI.csproj index c8c80cfa84..b8b59ab4d1 100644 --- a/samples/core/Modeling/FluentAPI/FluentAPI.csproj +++ b/samples/core/Modeling/FluentAPI/FluentAPI.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Modeling/FluentAPI/IgnoreProperty.cs b/samples/core/Modeling/FluentAPI/IgnoreProperty.cs index 6a633caf19..02aa0b15a6 100644 --- a/samples/core/Modeling/FluentAPI/IgnoreProperty.cs +++ b/samples/core/Modeling/FluentAPI/IgnoreProperty.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.IgnoreProperty { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IgnoreType.cs b/samples/core/Modeling/FluentAPI/IgnoreType.cs index 9d109d39ad..86c5437e65 100644 --- a/samples/core/Modeling/FluentAPI/IgnoreType.cs +++ b/samples/core/Modeling/FluentAPI/IgnoreType.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.IgnoreType { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Index.cs b/samples/core/Modeling/FluentAPI/Index.cs index 87f3dde367..6dda4860f1 100644 --- a/samples/core/Modeling/FluentAPI/Index.cs +++ b/samples/core/Modeling/FluentAPI/Index.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Index { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IndexComposite.cs b/samples/core/Modeling/FluentAPI/IndexComposite.cs index 9693ed6afa..1642a87bb4 100644 --- a/samples/core/Modeling/FluentAPI/IndexComposite.cs +++ b/samples/core/Modeling/FluentAPI/IndexComposite.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.IndexComposite { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet People { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IndexFilter.cs b/samples/core/Modeling/FluentAPI/IndexFilter.cs index 95f97d60c4..374489d6cd 100644 --- a/samples/core/Modeling/FluentAPI/IndexFilter.cs +++ b/samples/core/Modeling/FluentAPI/IndexFilter.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.IndexFilter { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IndexInclude.cs b/samples/core/Modeling/FluentAPI/IndexInclude.cs index 72c4ae3363..8b2db72e6b 100644 --- a/samples/core/Modeling/FluentAPI/IndexInclude.cs +++ b/samples/core/Modeling/FluentAPI/IndexInclude.cs @@ -3,7 +3,7 @@ namespace EFModeling.FluentAPI.Relational.IndexInclude { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Posts { get; set; } @@ -12,11 +12,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasIndex(p => p.Url) - .IncludeProperties(p => new - { - p.Title, - p.PublishedOn - }); + .IncludeProperties( + p => new { p.Title, p.PublishedOn }); } #endregion } diff --git a/samples/core/Modeling/FluentAPI/IndexName.cs b/samples/core/Modeling/FluentAPI/IndexName.cs index bf543850e3..a43a6a6a1a 100644 --- a/samples/core/Modeling/FluentAPI/IndexName.cs +++ b/samples/core/Modeling/FluentAPI/IndexName.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.IndexName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IndexNoFilter.cs b/samples/core/Modeling/FluentAPI/IndexNoFilter.cs index 22e7eb96c8..cdfe4e80ec 100644 --- a/samples/core/Modeling/FluentAPI/IndexNoFilter.cs +++ b/samples/core/Modeling/FluentAPI/IndexNoFilter.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.IndexNoFilter { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IndexUnique.cs b/samples/core/Modeling/FluentAPI/IndexUnique.cs index 8592af98a7..e57aeb9a7e 100644 --- a/samples/core/Modeling/FluentAPI/IndexUnique.cs +++ b/samples/core/Modeling/FluentAPI/IndexUnique.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.IndexUnique { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/IndexerProperty.cs b/samples/core/Modeling/FluentAPI/IndexerProperty.cs index 21b3291b58..dfdef7e881 100644 --- a/samples/core/Modeling/FluentAPI/IndexerProperty.cs +++ b/samples/core/Modeling/FluentAPI/IndexerProperty.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.IndexerProperty { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } @@ -18,13 +18,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) public class Blog { - private readonly Dictionary _data = new Dictionary(); + private readonly Dictionary _data = new Dictionary(); public int BlogId { get; set; } + public object this[string key] { get => _data[key]; set => _data[key] = value; - } } } diff --git a/samples/core/Modeling/FluentAPI/KeyComposite.cs b/samples/core/Modeling/FluentAPI/KeyComposite.cs index 7b3325f151..674fb5c5c7 100644 --- a/samples/core/Modeling/FluentAPI/KeyComposite.cs +++ b/samples/core/Modeling/FluentAPI/KeyComposite.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.KeyComposite { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } @@ -15,7 +15,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #endregion } - class Car + internal class Car { public string State { get; set; } public string LicensePlate { get; set; } diff --git a/samples/core/Modeling/FluentAPI/KeyName.cs b/samples/core/Modeling/FluentAPI/KeyName.cs index 78f31a419b..2aa3c8a8d4 100644 --- a/samples/core/Modeling/FluentAPI/KeyName.cs +++ b/samples/core/Modeling/FluentAPI/KeyName.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.KeyName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/KeySingle.cs b/samples/core/Modeling/FluentAPI/KeySingle.cs index c4bd7026df..e3a5eb64a3 100644 --- a/samples/core/Modeling/FluentAPI/KeySingle.cs +++ b/samples/core/Modeling/FluentAPI/KeySingle.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.KeySingle { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } @@ -15,7 +15,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #endregion } - class Car + internal class Car { public string LicensePlate { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Keyless.cs b/samples/core/Modeling/FluentAPI/Keyless.cs index 607a641a02..1d8819192e 100644 --- a/samples/core/Modeling/FluentAPI/Keyless.cs +++ b/samples/core/Modeling/FluentAPI/Keyless.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Keyless { - class BlogsContext : DbContext + internal class BlogsContext : DbContext { public DbSet BlogPostCounts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/MaxLength.cs b/samples/core/Modeling/FluentAPI/MaxLength.cs index 722f74442f..b6a26596c5 100644 --- a/samples/core/Modeling/FluentAPI/MaxLength.cs +++ b/samples/core/Modeling/FluentAPI/MaxLength.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.MaxLength { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/PrecisionAndScale.cs b/samples/core/Modeling/FluentAPI/PrecisionAndScale.cs index 5812707e95..418bd17c62 100644 --- a/samples/core/Modeling/FluentAPI/PrecisionAndScale.cs +++ b/samples/core/Modeling/FluentAPI/PrecisionAndScale.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.PrecisionAndScale { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Program.cs b/samples/core/Modeling/FluentAPI/Program.cs index 8efff7eac9..cb9a6beb87 100644 --- a/samples/core/Modeling/FluentAPI/Program.cs +++ b/samples/core/Modeling/FluentAPI/Program.cs @@ -1,10 +1,8 @@ -using Microsoft.EntityFrameworkCore; - -namespace EFModeling.FluentAPI +namespace EFModeling.FluentAPI { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { } } diff --git a/samples/core/Modeling/FluentAPI/Relationships/CascadeDelete.cs b/samples/core/Modeling/FluentAPI/Relationships/CascadeDelete.cs index b3dd47576a..521dd3be1d 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/CascadeDelete.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/CascadeDelete.cs @@ -1,10 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.CascadeDelete { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/CompositeForeignKey.cs b/samples/core/Modeling/FluentAPI/Relationships/CompositeForeignKey.cs index 81764b7ab9..8868c824fc 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/CompositeForeignKey.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/CompositeForeignKey.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Configuring.DataAnnotations.Samples.Relationships.CompositeForeignKey { #region CompositeForeignKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/CompositePrincipalKey.cs b/samples/core/Modeling/FluentAPI/Relationships/CompositePrincipalKey.cs index 7e8dc3244d..47e2bbb222 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/CompositePrincipalKey.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/CompositePrincipalKey.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Configuring.DataAnnotations.Samples.Relationships.CompositePrincipalKey { #region CompositePrincipalKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/ConstraintName.cs b/samples/core/Modeling/FluentAPI/Relationships/ConstraintName.cs index 61421fcd66..11ca4e3dc1 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/ConstraintName.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/ConstraintName.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.ConstraintName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/ForeignKey.cs b/samples/core/Modeling/FluentAPI/Relationships/ForeignKey.cs index bd89bbe3b4..5c89bcb7c0 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/ForeignKey.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/ForeignKey.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Configuring.DataAnnotations.Samples.Relationships.ForeignKey { #region ForeignKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/Full.cs b/samples/core/Modeling/FluentAPI/Relationships/Full.cs index 6e8e44c802..7696c95eae 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/Full.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/Full.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.Full { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/ManyToMany.cs b/samples/core/Modeling/FluentAPI/Relationships/ManyToMany.cs index e83482172d..117635c19b 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/ManyToMany.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/ManyToMany.cs @@ -1,6 +1,6 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.ManyToMany { diff --git a/samples/core/Modeling/FluentAPI/Relationships/ManyToManyPayload.cs b/samples/core/Modeling/FluentAPI/Relationships/ManyToManyPayload.cs index 03012cc001..d310fa28be 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/ManyToManyPayload.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/ManyToManyPayload.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.ManyToManyPayload { #region ManyToManyPayload - class MyContext : DbContext + internal class MyContext : DbContext { public MyContext(DbContextOptions options) : base(options) diff --git a/samples/core/Modeling/FluentAPI/Relationships/ManyToManyShared.cs b/samples/core/Modeling/FluentAPI/Relationships/ManyToManyShared.cs index 2aa278d5fe..27d1cad3e4 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/ManyToManyShared.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/ManyToManyShared.cs @@ -1,6 +1,6 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.ManyToManyShared { @@ -37,7 +37,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #region Seeding modelBuilder .Entity() - .HasData(new Post { PostId = 1, Title = "First"}); + .HasData(new Post { PostId = 1, Title = "First" }); modelBuilder .Entity() diff --git a/samples/core/Modeling/FluentAPI/Relationships/NavigationConfiguration.cs b/samples/core/Modeling/FluentAPI/Relationships/NavigationConfiguration.cs index 683911b5b5..f087777fc3 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/NavigationConfiguration.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/NavigationConfiguration.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.NavigationConfiguration { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } @@ -17,7 +17,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .Navigation(b => b.Posts) - .UsePropertyAccessMode(PropertyAccessMode.Property); + .UsePropertyAccessMode(PropertyAccessMode.Property); } #endregion } diff --git a/samples/core/Modeling/FluentAPI/Relationships/NoForeignKey.cs b/samples/core/Modeling/FluentAPI/Relationships/NoForeignKey.cs index 9249d8834b..9348fdee01 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/NoForeignKey.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/NoForeignKey.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.NoForeignKey { #region NoForeignKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/NoNavigation.cs b/samples/core/Modeling/FluentAPI/Relationships/NoNavigation.cs index 4f8d3791f2..129f68c2c7 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/NoNavigation.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/NoNavigation.cs @@ -1,10 +1,9 @@ using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; namespace EFModeling.FluentAPI.Relationships.NoNavigation { #region NoNavigation - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/OneNavigation.cs b/samples/core/Modeling/FluentAPI/Relationships/OneNavigation.cs index 210ef836c7..f9f5de404e 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/OneNavigation.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/OneNavigation.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.OneNavigation { #region OneNavigation - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/OneToOne.cs b/samples/core/Modeling/FluentAPI/Relationships/OneToOne.cs index f93745a7aa..d5a52cbdc1 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/OneToOne.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/OneToOne.cs @@ -1,10 +1,9 @@ using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; namespace EFModeling.FluentAPI.Relationships.OneToOne { #region OneToOne - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet BlogImages { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/PrincipalKey.cs b/samples/core/Modeling/FluentAPI/Relationships/PrincipalKey.cs index 9339a37222..52eb38b989 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/PrincipalKey.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/PrincipalKey.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Configuring.DataAnnotations.Samples.Relationships.PrincipalKey { #region PrincipalKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Cars { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/Required.cs b/samples/core/Modeling/FluentAPI/Relationships/Required.cs index 7b0fb25e80..58bc565175 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/Required.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/Required.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.Relationships.Required { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Relationships/ShadowForeignKey.cs b/samples/core/Modeling/FluentAPI/Relationships/ShadowForeignKey.cs index 6f268d1af3..5b44c38e79 100644 --- a/samples/core/Modeling/FluentAPI/Relationships/ShadowForeignKey.cs +++ b/samples/core/Modeling/FluentAPI/Relationships/ShadowForeignKey.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.Configuring.DataAnnotations.Samples.Relationships.ShadowForeignKey { #region ShadowForeignKey - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } public DbSet Posts { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Required.cs b/samples/core/Modeling/FluentAPI/Required.cs index 4e6b9d350f..a6453e6be5 100644 --- a/samples/core/Modeling/FluentAPI/Required.cs +++ b/samples/core/Modeling/FluentAPI/Required.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Required { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Sequence.cs b/samples/core/Modeling/FluentAPI/Sequence.cs index 6b81d14a47..26f1c2dda6 100644 --- a/samples/core/Modeling/FluentAPI/Sequence.cs +++ b/samples/core/Modeling/FluentAPI/Sequence.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.Sequence { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Orders { get; set; } diff --git a/samples/core/Modeling/FluentAPI/SequenceConfiguration.cs b/samples/core/Modeling/FluentAPI/SequenceConfiguration.cs index b7b245eefa..fc9424dcee 100644 --- a/samples/core/Modeling/FluentAPI/SequenceConfiguration.cs +++ b/samples/core/Modeling/FluentAPI/SequenceConfiguration.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.SequenceConfiguration { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Orders { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ShadowProperty.cs b/samples/core/Modeling/FluentAPI/ShadowProperty.cs index 18a88900ec..4227e1a354 100644 --- a/samples/core/Modeling/FluentAPI/ShadowProperty.cs +++ b/samples/core/Modeling/FluentAPI/ShadowProperty.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.ShadowProperty { #region ShadowProperty - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/SharedType.cs b/samples/core/Modeling/FluentAPI/SharedType.cs index 5f1af27a3a..8f6027ea67 100644 --- a/samples/core/Modeling/FluentAPI/SharedType.cs +++ b/samples/core/Modeling/FluentAPI/SharedType.cs @@ -1,22 +1,23 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.SharedType { #region SharedType - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet> Blogs => Set>("Blog"); protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.SharedTypeEntity>("Blog", bb => - { - bb.Property("BlogId"); - bb.Property("Url"); - bb.Property("LastUpdated"); - }); + modelBuilder.SharedTypeEntity>( + "Blog", bb => + { + bb.Property("BlogId"); + bb.Property("Url"); + bb.Property("LastUpdated"); + }); } } #endregion diff --git a/samples/core/Modeling/FluentAPI/TPTConfiguration.cs b/samples/core/Modeling/FluentAPI/TPTConfiguration.cs index 9cd565f21e..152482f381 100644 --- a/samples/core/Modeling/FluentAPI/TPTConfiguration.cs +++ b/samples/core/Modeling/FluentAPI/TPTConfiguration.cs @@ -1,6 +1,6 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; -using System; namespace EFModeling.FluentAPI.TPTConfiguration { diff --git a/samples/core/Modeling/FluentAPI/TableComment.cs b/samples/core/Modeling/FluentAPI/TableComment.cs index 19e63d434b..c7748a20b2 100644 --- a/samples/core/Modeling/FluentAPI/TableComment.cs +++ b/samples/core/Modeling/FluentAPI/TableComment.cs @@ -1,9 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System; namespace EFModeling.FluentAPI.TableComment { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/TableExcludeFromMigrations.cs b/samples/core/Modeling/FluentAPI/TableExcludeFromMigrations.cs index 38f557c746..f90091ff01 100644 --- a/samples/core/Modeling/FluentAPI/TableExcludeFromMigrations.cs +++ b/samples/core/Modeling/FluentAPI/TableExcludeFromMigrations.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.TableExcludeFromMigrations { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Users { get; set; } diff --git a/samples/core/Modeling/FluentAPI/TableName.cs b/samples/core/Modeling/FluentAPI/TableName.cs index 30a0191856..d208432f0c 100644 --- a/samples/core/Modeling/FluentAPI/TableName.cs +++ b/samples/core/Modeling/FluentAPI/TableName.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.TableName { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/TableNameAndSchema.cs b/samples/core/Modeling/FluentAPI/TableNameAndSchema.cs index f05810a1f1..167f71501c 100644 --- a/samples/core/Modeling/FluentAPI/TableNameAndSchema.cs +++ b/samples/core/Modeling/FluentAPI/TableNameAndSchema.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.TableNameAndSchema { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/Timestamp.cs b/samples/core/Modeling/FluentAPI/Timestamp.cs index dbd1f51cce..b4c98498db 100644 --- a/samples/core/Modeling/FluentAPI/Timestamp.cs +++ b/samples/core/Modeling/FluentAPI/Timestamp.cs @@ -3,7 +3,7 @@ namespace EFModeling.FluentAPI.Timestamp { #region Timestamp - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ValueGeneratedNever.cs b/samples/core/Modeling/FluentAPI/ValueGeneratedNever.cs index e0f924094a..56e328013f 100644 --- a/samples/core/Modeling/FluentAPI/ValueGeneratedNever.cs +++ b/samples/core/Modeling/FluentAPI/ValueGeneratedNever.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.ValueGeneratedNever { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ValueGeneratedOnAdd.cs b/samples/core/Modeling/FluentAPI/ValueGeneratedOnAdd.cs index c53bbe8c12..82392f5dd0 100644 --- a/samples/core/Modeling/FluentAPI/ValueGeneratedOnAdd.cs +++ b/samples/core/Modeling/FluentAPI/ValueGeneratedOnAdd.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.ValueGeneratedOnAdd { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdate.cs b/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdate.cs index 1e32faa93c..a6a4008770 100644 --- a/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdate.cs +++ b/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdate.cs @@ -1,9 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; namespace EFModeling.FluentAPI.ValueGeneratedOnAddOrUpdate { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdateWithPropertySaveBehavior.cs b/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdateWithPropertySaveBehavior.cs index df7e734281..50629d2b52 100644 --- a/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdateWithPropertySaveBehavior.cs +++ b/samples/core/Modeling/FluentAPI/ValueGeneratedOnAddOrUpdateWithPropertySaveBehavior.cs @@ -1,10 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System; +using System; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; namespace EFModeling.FluentAPI.ValueGeneratedOnAddOrUpdateWithPropertySaveBehavior { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/FluentAPI/ViewNameAndSchema.cs b/samples/core/Modeling/FluentAPI/ViewNameAndSchema.cs index 5862d8968f..b18180ee94 100644 --- a/samples/core/Modeling/FluentAPI/ViewNameAndSchema.cs +++ b/samples/core/Modeling/FluentAPI/ViewNameAndSchema.cs @@ -2,7 +2,7 @@ namespace EFModeling.FluentAPI.Relational.ViewNameAndSchema { - class MyContext : DbContext + internal class MyContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Modeling/OwnedEntities/OwnedEntities.csproj b/samples/core/Modeling/OwnedEntities/OwnedEntities.csproj index dd7d2f65f7..e6e82a6ff4 100644 --- a/samples/core/Modeling/OwnedEntities/OwnedEntities.csproj +++ b/samples/core/Modeling/OwnedEntities/OwnedEntities.csproj @@ -8,11 +8,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/samples/core/Modeling/OwnedEntities/OwnedEntityContext.cs b/samples/core/Modeling/OwnedEntities/OwnedEntityContext.cs index 5958fe6d56..2af22380da 100644 --- a/samples/core/Modeling/OwnedEntities/OwnedEntityContext.cs +++ b/samples/core/Modeling/OwnedEntities/OwnedEntityContext.cs @@ -32,45 +32,45 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #endregion #region Required - modelBuilder.Entity(ob => - { - ob.OwnsOne( - o => o.ShippingAddress, - sa => - { - sa.Property(p => p.Street).IsRequired(); - sa.Property(p => p.City).IsRequired(); - }); + modelBuilder.Entity( + ob => + { + ob.OwnsOne( + o => o.ShippingAddress, + sa => + { + sa.Property(p => p.Street).IsRequired(); + sa.Property(p => p.City).IsRequired(); + }); - ob.Navigation(o => o.ShippingAddress) - .IsRequired(); - }); + ob.Navigation(o => o.ShippingAddress) + .IsRequired(); + }); #endregion #region OwnsOneNested - modelBuilder.Entity().OwnsOne(p => p.OrderDetails, od => - { - od.WithOwner(d => d.Order); - od.Navigation(d => d.Order).UsePropertyAccessMode(PropertyAccessMode.Property); - od.OwnsOne(c => c.BillingAddress); - od.OwnsOne(c => c.ShippingAddress); - }); + modelBuilder.Entity().OwnsOne( + p => p.OrderDetails, od => + { + od.WithOwner(d => d.Order); + od.Navigation(d => d.Order).UsePropertyAccessMode(PropertyAccessMode.Property); + od.OwnsOne(c => c.BillingAddress); + od.OwnsOne(c => c.ShippingAddress); + }); #endregion #region OwnsOneTable - modelBuilder.Entity().OwnsOne(p => p.OrderDetails, od => - { - od.ToTable("OrderDetails"); - }); + modelBuilder.Entity().OwnsOne(p => p.OrderDetails, od => { od.ToTable("OrderDetails"); }); #endregion #region OwnsMany - modelBuilder.Entity().OwnsMany(p => p.ShippingCenters, a => - { - a.WithOwner().HasForeignKey("OwnerId"); - a.Property("Id"); - a.HasKey("Id"); - }); + modelBuilder.Entity().OwnsMany( + p => p.ShippingCenters, a => + { + a.WithOwner().HasForeignKey("OwnerId"); + a.Property("Id"); + a.HasKey("Id"); + }); #endregion } } diff --git a/samples/core/Modeling/OwnedEntities/Program.cs b/samples/core/Modeling/OwnedEntities/Program.cs index 7589132bb5..de1c06406d 100644 --- a/samples/core/Modeling/OwnedEntities/Program.cs +++ b/samples/core/Modeling/OwnedEntities/Program.cs @@ -5,22 +5,23 @@ namespace EFModeling.OwnedEntities { public static class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new OwnedEntityContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); - context.Add(new DetailedOrder - { - Status = OrderStatus.Pending, - OrderDetails = new OrderDetails + context.Add( + new DetailedOrder { - ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, - BillingAddress = new StreetAddress { City = "New York", Street = "11 Wall Street" } - } - }); + Status = OrderStatus.Pending, + OrderDetails = new OrderDetails + { + ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, + BillingAddress = new StreetAddress { City = "New York", Street = "11 Wall Street" } + } + }); context.SaveChanges(); } diff --git a/samples/core/Modeling/TableSplitting/Program.cs b/samples/core/Modeling/TableSplitting/Program.cs index 1ffec06e5c..9ee326c4e1 100644 --- a/samples/core/Modeling/TableSplitting/Program.cs +++ b/samples/core/Modeling/TableSplitting/Program.cs @@ -5,7 +5,7 @@ namespace EFModeling.TableSplitting { public static class Program { - static void Main(string[] args) + private static void Main(string[] args) { #region Usage using (var context = new TableSplittingContext()) @@ -13,16 +13,17 @@ static void Main(string[] args) context.Database.EnsureDeleted(); context.Database.EnsureCreated(); - context.Add(new Order - { - Status = OrderStatus.Pending, - DetailedOrder = new DetailedOrder + context.Add( + new Order { Status = OrderStatus.Pending, - ShippingAddress = "221 B Baker St, London", - BillingAddress = "11 Wall Street, New York" - } - }); + DetailedOrder = new DetailedOrder + { + Status = OrderStatus.Pending, + ShippingAddress = "221 B Baker St, London", + BillingAddress = "11 Wall Street, New York" + } + }); context.SaveChanges(); } diff --git a/samples/core/Modeling/TableSplitting/TableSplitting.csproj b/samples/core/Modeling/TableSplitting/TableSplitting.csproj index 145f73e6e7..dab889bfad 100644 --- a/samples/core/Modeling/TableSplitting/TableSplitting.csproj +++ b/samples/core/Modeling/TableSplitting/TableSplitting.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Modeling/TableSplitting/TableSplittingContext.cs b/samples/core/Modeling/TableSplitting/TableSplittingContext.cs index b01114f3c3..59ff12104d 100644 --- a/samples/core/Modeling/TableSplitting/TableSplittingContext.cs +++ b/samples/core/Modeling/TableSplitting/TableSplittingContext.cs @@ -14,20 +14,21 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { #region TableSplitting - modelBuilder.Entity(dob => - { - dob.ToTable("Orders"); - dob.Property(o => o.Status).HasColumnName("Status"); - }); - - modelBuilder.Entity(ob => - { - ob.ToTable("Orders"); - ob.Property(o => o.Status).HasColumnName("Status"); - ob.HasOne(o => o.DetailedOrder).WithOne() - .HasForeignKey(o => o.Id); - }); + modelBuilder.Entity( + dob => + { + dob.ToTable("Orders"); + dob.Property(o => o.Status).HasColumnName("Status"); + }); + modelBuilder.Entity( + ob => + { + ob.ToTable("Orders"); + ob.Property(o => o.Status).HasColumnName("Status"); + ob.HasOne(o => o.DetailedOrder).WithOne() + .HasForeignKey(o => o.Id); + }); #endregion #region ConcurrencyToken diff --git a/samples/core/Modeling/ValueConversions/MappingImmutableClassProperty.cs b/samples/core/Modeling/ValueConversions/MappingImmutableClassProperty.cs index 7e0d107a0d..176d53bdd5 100644 --- a/samples/core/Modeling/ValueConversions/MappingImmutableClassProperty.cs +++ b/samples/core/Modeling/ValueConversions/MappingImmutableClassProperty.cs @@ -55,7 +55,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasConversion( v => v.Value, v => new ImmutableClass(v)); - #endregion } diff --git a/samples/core/Modeling/ValueConversions/OverridingByteArrayComparisons.cs b/samples/core/Modeling/ValueConversions/OverridingByteArrayComparisons.cs index 53989e6e4f..9d53630b2b 100644 --- a/samples/core/Modeling/ValueConversions/OverridingByteArrayComparisons.cs +++ b/samples/core/Modeling/ValueConversions/OverridingByteArrayComparisons.cs @@ -56,10 +56,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .Entity() .Property(e => e.MyBytes) .Metadata - .SetValueComparer(new ValueComparer( - (c1, c2) => c1.SequenceEqual(c2), - c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), - c => c.ToArray())); + .SetValueComparer( + new ValueComparer( + (c1, c2) => c1.SequenceEqual(c2), + c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), + c => c.ToArray())); #endregion } diff --git a/samples/core/Modeling/ValueConversions/Program.cs b/samples/core/Modeling/ValueConversions/Program.cs index 2bc4edf6cc..6512932743 100644 --- a/samples/core/Modeling/ValueConversions/Program.cs +++ b/samples/core/Modeling/ValueConversions/Program.cs @@ -4,7 +4,7 @@ namespace EFModeling.ValueConversions { /// - /// Samples for value conversions and comparisons. + /// Samples for value conversions and comparisons. /// public class Program { @@ -24,6 +24,7 @@ protected static void ConsoleWriteLines(params string[] values) { Console.WriteLine(value); } + Console.WriteLine(); } diff --git a/samples/core/Modeling/ValueConversions/ValueConversions.csproj b/samples/core/Modeling/ValueConversions/ValueConversions.csproj index cc4560ac41..797bf55a77 100644 --- a/samples/core/Modeling/ValueConversions/ValueConversions.csproj +++ b/samples/core/Modeling/ValueConversions/ValueConversions.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Performance/BatchTweakingContext.cs b/samples/core/Performance/BatchTweakingContext.cs index c0721633e7..2f31026d7a 100644 --- a/samples/core/Performance/BatchTweakingContext.cs +++ b/samples/core/Performance/BatchTweakingContext.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using Microsoft.EntityFrameworkCore; namespace Performance diff --git a/samples/core/Performance/BloggingContext.cs b/samples/core/Performance/BloggingContext.cs index 3de862a903..5cba9767c5 100644 --- a/samples/core/Performance/BloggingContext.cs +++ b/samples/core/Performance/BloggingContext.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; diff --git a/samples/core/Performance/EmployeeContext.cs b/samples/core/Performance/EmployeeContext.cs index 514f99187e..f6f9a7e5cb 100644 --- a/samples/core/Performance/EmployeeContext.cs +++ b/samples/core/Performance/EmployeeContext.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; diff --git a/samples/core/Performance/ExtensionsLoggingContext.cs b/samples/core/Performance/ExtensionsLoggingContext.cs index 4a61854eb4..6363847296 100644 --- a/samples/core/Performance/ExtensionsLoggingContext.cs +++ b/samples/core/Performance/ExtensionsLoggingContext.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; diff --git a/samples/core/Performance/LazyLoading/LazyBloggingContext.cs b/samples/core/Performance/LazyLoading/LazyBloggingContext.cs index decd32aac0..a88bc15e1b 100644 --- a/samples/core/Performance/LazyLoading/LazyBloggingContext.cs +++ b/samples/core/Performance/LazyLoading/LazyBloggingContext.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; diff --git a/samples/core/Performance/Performance.csproj b/samples/core/Performance/Performance.csproj index ab40efd566..625f6d2b33 100644 --- a/samples/core/Performance/Performance.csproj +++ b/samples/core/Performance/Performance.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/samples/core/Performance/Program.cs b/samples/core/Performance/Program.cs index 12f31ab5f0..d81550419f 100644 --- a/samples/core/Performance/Program.cs +++ b/samples/core/Performance/Program.cs @@ -6,14 +6,28 @@ namespace Performance { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new BloggingContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); + + context.Add( + new Blog + { + Url = "http://someblog.microsoft.com", + Rating = 0, + Posts = new List + { + new Post { Title = "Post 1", Content = "Sometimes..." }, + new Post { Title = "Post 2", Content = "Other times..." } + } + }); + + context.SaveChanges(); } using (var context = new BloggingContext()) @@ -102,8 +116,8 @@ static void Main(string[] args) #region SaveChangesBatching var blog = context.Blogs.Single(b => b.Url == "http://someblog.microsoft.com"); blog.Url = "http://someotherblog.microsoft.com"; - context.Add(new Blog { Url = "http://newblog1.microsoft.com"}); - context.Add(new Blog { Url = "http://newblog2.microsoft.com"}); + context.Add(new Blog { Url = "http://newblog1.microsoft.com" }); + context.Add(new Blog { Url = "http://newblog2.microsoft.com" }); context.SaveChanges(); #endregion } @@ -133,15 +147,15 @@ static void Main(string[] args) for (var i = 0; i < 10; i++) { - context.Blogs.Add(new LazyLoading.Blog - { - Url = $"http://blog{i}.microsoft.com", - Posts = new List + context.Blogs.Add( + new LazyLoading.Blog { - new() { Title = $"1st post of blog{i}" }, - new() { Title = $"2nd post of blog{i}" } - } - }); + Url = $"http://blog{i}.microsoft.com", + Posts = new List + { + new() { Title = $"1st post of blog{i}" }, new() { Title = $"2nd post of blog{i}" } + } + }); } context.SaveChanges(); @@ -178,6 +192,7 @@ static void Main(string[] args) { employee.Salary += 1000; } + context.SaveChanges(); #endregion } diff --git a/samples/core/Querying/ClientEvaluation/BloggingContext.cs b/samples/core/Querying/ClientEvaluation/BloggingContext.cs index 82fb21e568..ae05bc27bb 100644 --- a/samples/core/Querying/ClientEvaluation/BloggingContext.cs +++ b/samples/core/Querying/ClientEvaluation/BloggingContext.cs @@ -16,7 +16,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.ClientEvaluation;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.ClientEvaluation;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/ClientEvaluation/ClientEvaluation.csproj b/samples/core/Querying/ClientEvaluation/ClientEvaluation.csproj index 5a9e944fa2..ada35234e9 100644 --- a/samples/core/Querying/ClientEvaluation/ClientEvaluation.csproj +++ b/samples/core/Querying/ClientEvaluation/ClientEvaluation.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/ClientEvaluation/Program.cs b/samples/core/Querying/ClientEvaluation/Program.cs index ed45104efd..82b4d75f53 100644 --- a/samples/core/Querying/ClientEvaluation/Program.cs +++ b/samples/core/Querying/ClientEvaluation/Program.cs @@ -3,7 +3,7 @@ namespace EFQuerying.ClientEvaluation { - class Program + internal class Program { #region ClientMethod public static string StandardizeUrl(string url) @@ -19,18 +19,21 @@ public static string StandardizeUrl(string url) } #endregion - static void Main(string[] args) + private static void Main(string[] args) { + using (var context = new BloggingContext()) + { + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + } + using (var context = new BloggingContext()) { #region ClientProjection var blogs = context.Blogs .OrderByDescending(blog => blog.Rating) - .Select(blog => new - { - Id = blog.BlogId, - Url = StandardizeUrl(blog.Url) - }) + .Select( + blog => new { Id = blog.BlogId, Url = StandardizeUrl(blog.Url) }) .ToList(); #endregion } diff --git a/samples/core/Querying/ComplexQuery/BloggingContext.cs b/samples/core/Querying/ComplexQuery/BloggingContext.cs index 6a054319c4..22b468857d 100644 --- a/samples/core/Querying/ComplexQuery/BloggingContext.cs +++ b/samples/core/Querying/ComplexQuery/BloggingContext.cs @@ -26,15 +26,50 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasData( - new Blog { BlogId = 1, Url = @"https://devblogs.microsoft.com/dotnet", Rating = 5, OwnerId = 1, }, + new Blog + { + BlogId = 1, Url = @"https://devblogs.microsoft.com/dotnet", Rating = 5, OwnerId = 1, + }, new Blog { BlogId = 2, Url = @"https://mytravelblog.com/", Rating = 4, OwnerId = 3 }); modelBuilder.Entity() .HasData( - new Post { PostId = 1, BlogId = 1, Title = "What's new", Content = "Lorem ipsum dolor sit amet", Rating = 5, AuthorId = 1 }, - new Post { PostId = 2, BlogId = 2, Title = "Around the World in Eighty Days", Content = "consectetur adipiscing elit", Rating = 5, AuthorId = 2 }, - new Post { PostId = 3, BlogId = 2, Title = "Glamping *is* the way", Content = "sed do eiusmod tempor incididunt", Rating = 4, AuthorId = 3 }, - new Post { PostId = 4, BlogId = 2, Title = "Travel in the time of pandemic", Content = "ut labore et dolore magna aliqua", Rating = 3, AuthorId = 3 }); + new Post + { + PostId = 1, + BlogId = 1, + Title = "What's new", + Content = "Lorem ipsum dolor sit amet", + Rating = 5, + AuthorId = 1 + }, + new Post + { + PostId = 2, + BlogId = 2, + Title = "Around the World in Eighty Days", + Content = "consectetur adipiscing elit", + Rating = 5, + AuthorId = 2 + }, + new Post + { + PostId = 3, + BlogId = 2, + Title = "Glamping *is* the way", + Content = "sed do eiusmod tempor incididunt", + Rating = 4, + AuthorId = 3 + }, + new Post + { + PostId = 4, + BlogId = 2, + Title = "Travel in the time of pandemic", + Content = "ut labore et dolore magna aliqua", + Rating = 3, + AuthorId = 3 + }); modelBuilder.Entity() .HasData( @@ -67,7 +102,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.ComplexQuery;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.ComplexQuery;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/ComplexQuery/ComplexQuery.csproj b/samples/core/Querying/ComplexQuery/ComplexQuery.csproj index 4c7a19985e..973ee02e11 100644 --- a/samples/core/Querying/ComplexQuery/ComplexQuery.csproj +++ b/samples/core/Querying/ComplexQuery/ComplexQuery.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/ComplexQuery/Program.cs b/samples/core/Querying/ComplexQuery/Program.cs index 87654a9690..de83b87bda 100644 --- a/samples/core/Querying/ComplexQuery/Program.cs +++ b/samples/core/Querying/ComplexQuery/Program.cs @@ -1,11 +1,10 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; namespace EFQuerying.ComplexQuery { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new BloggingContext()) { @@ -22,7 +21,7 @@ on photo.PersonPhotoId equals person.PhotoId #region JoinComposite var query = from photo in context.Set() join person in context.Set() - on new { Id = (int?)photo.PersonPhotoId, Caption = photo.Caption } + on new { Id = (int?)photo.PersonPhotoId, photo.Caption } equals new { Id = person.PhotoId, Caption = "SN" } select new { person, photo }; #endregion @@ -87,12 +86,9 @@ from p in context.Set().Select(p => b.Url + "=>" + p.Title).DefaultIfEmpty { #region GroupBy var query = from p in context.Set() - group p by p.AuthorId into g - select new - { - g.Key, - Count = g.Count() - }; + group p by p.AuthorId + into g + select new { g.Key, Count = g.Count() }; #endregion } @@ -100,14 +96,11 @@ group p by p.AuthorId into g { #region GroupByFilter var query = from p in context.Set() - group p by p.AuthorId into g + group p by p.AuthorId + into g where g.Count() > 0 orderby g.Key - select new - { - g.Key, - Count = g.Count() - }; + select new { g.Key, Count = g.Count() }; #endregion } diff --git a/samples/core/Querying/NullSemantics/NullSemantics.csproj b/samples/core/Querying/NullSemantics/NullSemantics.csproj index 435f501fb5..b1f0a506b8 100644 --- a/samples/core/Querying/NullSemantics/NullSemantics.csproj +++ b/samples/core/Querying/NullSemantics/NullSemantics.csproj @@ -6,7 +6,7 @@ - + diff --git a/samples/core/Querying/NullSemantics/NullSemanticsContext.cs b/samples/core/Querying/NullSemantics/NullSemanticsContext.cs index 8006342093..643c989430 100644 --- a/samples/core/Querying/NullSemantics/NullSemanticsContext.cs +++ b/samples/core/Querying/NullSemantics/NullSemanticsContext.cs @@ -13,21 +13,57 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) if (relationalNulls) { #region UseRelationalNulls - new SqlServerDbContextOptionsBuilder(optionsBuilder).UseRelationalNulls(true); + new SqlServerDbContextOptionsBuilder(optionsBuilder).UseRelationalNulls(); #endregion } - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=NullSemanticsSample;Trusted_Connection=True;MultipleActiveResultSets=true"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=NullSemanticsSample;Trusted_Connection=True;MultipleActiveResultSets=true"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasData( - new NullSemanticsEntity { Id = 1, Int = 1, NullableInt = 1, String1 = "A", String2 = "A" }, - new NullSemanticsEntity { Id = 2, Int = 2, NullableInt = 2, String1 = "A", String2 = "B" }, - new NullSemanticsEntity { Id = 3, Int = 2, NullableInt = null, String1 = null, String2 = "A" }, - new NullSemanticsEntity { Id = 4, Int = 2, NullableInt = null, String1 = "B", String2 = null }, - new NullSemanticsEntity { Id = 5, Int = 1, NullableInt = 3, String1 = null, String2 = null }); + new NullSemanticsEntity + { + Id = 1, + Int = 1, + NullableInt = 1, + String1 = "A", + String2 = "A" + }, + new NullSemanticsEntity + { + Id = 2, + Int = 2, + NullableInt = 2, + String1 = "A", + String2 = "B" + }, + new NullSemanticsEntity + { + Id = 3, + Int = 2, + NullableInt = null, + String1 = null, + String2 = "A" + }, + new NullSemanticsEntity + { + Id = 4, + Int = 2, + NullableInt = null, + String1 = "B", + String2 = null + }, + new NullSemanticsEntity + { + Id = 5, + Int = 1, + NullableInt = 3, + String1 = null, + String2 = null + }); } } } diff --git a/samples/core/Querying/NullSemantics/Program.cs b/samples/core/Querying/NullSemantics/Program.cs index 1bb66d468e..2e16eeecff 100644 --- a/samples/core/Querying/NullSemantics/Program.cs +++ b/samples/core/Querying/NullSemantics/Program.cs @@ -1,11 +1,10 @@ -using Microsoft.EntityFrameworkCore; -using System.Linq; +using System.Linq; namespace NullSemantics { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using var context = new NullSemanticsContext(); context.Database.EnsureDeleted(); @@ -26,7 +25,7 @@ static void Main(string[] args) //ManualOptimization(); } - static void BasicExamples() + private static void BasicExamples() { using var context = new NullSemanticsContext(); #region BasicExamples @@ -44,7 +43,7 @@ static void BasicExamples() var result5 = query5.ToList(); } - static void Functions() + private static void Functions() { using var context = new NullSemanticsContext(); @@ -55,13 +54,14 @@ static void Functions() var result = query.ToList(); } - static void ManualOptimization() + private static void ManualOptimization() { using var context = new NullSemanticsContext(); #region ManualOptimization var query1 = context.Entities.Where(e => e.String1 != e.String2 || e.String1.Length == e.String2.Length); - var query2 = context.Entities.Where(e => e.String1 != null && e.String2 != null && (e.String1 != e.String2 || e.String1.Length == e.String2.Length)); + var query2 = context.Entities.Where( + e => e.String1 != null && e.String2 != null && (e.String1 != e.String2 || e.String1.Length == e.String2.Length)); #endregion var result1 = query1.ToList(); diff --git a/samples/core/Querying/Overview/BloggingContext.cs b/samples/core/Querying/Overview/BloggingContext.cs index 57b3467e40..decad5b1d4 100644 --- a/samples/core/Querying/Overview/BloggingContext.cs +++ b/samples/core/Querying/Overview/BloggingContext.cs @@ -16,7 +16,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.Overview;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.Overview;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/Overview/Overview.csproj b/samples/core/Querying/Overview/Overview.csproj index cefcdb7802..80fcf02db0 100644 --- a/samples/core/Querying/Overview/Overview.csproj +++ b/samples/core/Querying/Overview/Overview.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/Overview/Program.cs b/samples/core/Querying/Overview/Program.cs index 0430e0d573..32d00d7952 100644 --- a/samples/core/Querying/Overview/Program.cs +++ b/samples/core/Querying/Overview/Program.cs @@ -2,10 +2,16 @@ namespace EFQuerying.Overview { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { + using (var context = new BloggingContext()) + { + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + } + #region LoadingAllData using (var context = new BloggingContext()) { diff --git a/samples/core/Querying/QueryFilters/AnimalContext.cs b/samples/core/Querying/QueryFilters/AnimalContext.cs index 8579805d90..21f49e5c6a 100644 --- a/samples/core/Querying/QueryFilters/AnimalContext.cs +++ b/samples/core/Querying/QueryFilters/AnimalContext.cs @@ -28,5 +28,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) //modelBuilder.Entity().HasQueryFilter(a => a.Owner.Name != "John"); } } - } diff --git a/samples/core/Querying/QueryFilters/BloggingContext.cs b/samples/core/Querying/QueryFilters/BloggingContext.cs index ac5f842465..71f206b752 100644 --- a/samples/core/Querying/QueryFilters/BloggingContext.cs +++ b/samples/core/Querying/QueryFilters/BloggingContext.cs @@ -1,5 +1,5 @@ -using Microsoft.EntityFrameworkCore; -using System.Linq; +using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFQuerying.QueryFilters { diff --git a/samples/core/Querying/QueryFilters/Program.cs b/samples/core/Querying/QueryFilters/Program.cs index 910e421ff0..5ecf4be514 100644 --- a/samples/core/Querying/QueryFilters/Program.cs +++ b/samples/core/Querying/QueryFilters/Program.cs @@ -5,9 +5,9 @@ namespace EFQuerying.QueryFilters { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { QueryFiltersBasicExample(); QueryFiltersWithNavigationsExample(); @@ -15,7 +15,7 @@ static void Main(string[] args) QueryFiltersUsingNavigationExample(); } - static void QueryFiltersBasicExample() + private static void QueryFiltersBasicExample() { using (var db = new BloggingContext("diego")) { @@ -55,8 +55,7 @@ static void QueryFiltersBasicExample() Url = "http://sample.com/blogs/catfish", Posts = new List { - new Post { Title = "Catfish care 101" }, - new Post { Title = "History of the catfish name" } + new Post { Title = "Catfish care 101" }, new Post { Title = "History of the catfish name" } } }); @@ -243,7 +242,6 @@ private static void QueryFiltersWithRequiredNavigationExample() Console.WriteLine("Use of required navigations to access entity with query filter demo"); using (var db = new FilteredBloggingContextRequired()) { - #region Queries var allPosts = db.Posts.ToList(); var allPostsWithBlogsIncluded = db.Posts.Include(p => p.Blog).ToList(); @@ -300,8 +298,7 @@ private static void QueryFiltersUsingNavigationExample() Url = "http://sample.com/blogs/catfish", Posts = new List { - new Post { Title = "Catfish care 101" }, - new Post { Title = "History of the catfish name" } + new Post { Title = "Catfish care 101" }, new Post { Title = "History of the catfish name" } } }); #endregion @@ -316,10 +313,12 @@ private static void QueryFiltersUsingNavigationExample() var filteredBlogs = db.Blogs.ToList(); #endregion var filteredBlogsInclude = db.Blogs.Include(b => b.Posts).ToList(); - if (filteredBlogs.Count == 2 && filteredBlogsInclude.Count == 2) + if (filteredBlogs.Count == 2 + && filteredBlogsInclude.Count == 2) { Console.WriteLine("Blogs without any Posts are also filtered out. Posts must contain 'fish' in title."); - Console.WriteLine("Filters are applied recursively, so Blogs that do have Posts, but those Posts don't contain 'fish' in the title will also be filtered out."); + Console.WriteLine( + "Filters are applied recursively, so Blogs that do have Posts, but those Posts don't contain 'fish' in the title will also be filtered out."); } } } diff --git a/samples/core/Querying/QueryFilters/QueryFilters.csproj b/samples/core/Querying/QueryFilters/QueryFilters.csproj index 71faad1772..b91c55fc06 100644 --- a/samples/core/Querying/QueryFilters/QueryFilters.csproj +++ b/samples/core/Querying/QueryFilters/QueryFilters.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/RawSQL/BloggingContext.cs b/samples/core/Querying/RawSQL/BloggingContext.cs index 03abc620c3..a97c7fd666 100644 --- a/samples/core/Querying/RawSQL/BloggingContext.cs +++ b/samples/core/Querying/RawSQL/BloggingContext.cs @@ -15,15 +15,44 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasData( - new Post { PostId = 1, BlogId = 1, Title = "What's new", Content = "Lorem ipsum dolor sit amet", Rating = 5 }, - new Post { PostId = 2, BlogId = 2, Title = "Around the World in Eighty Days", Content = "consectetur adipiscing elit", Rating = 5 }, - new Post { PostId = 3, BlogId = 2, Title = "Glamping *is* the way", Content = "sed do eiusmod tempor incididunt", Rating = 4 }, - new Post { PostId = 4, BlogId = 2, Title = "Travel in the time of pandemic", Content = "ut labore et dolore magna aliqua", Rating = 3 }); + new Post + { + PostId = 1, + BlogId = 1, + Title = "What's new", + Content = "Lorem ipsum dolor sit amet", + Rating = 5 + }, + new Post + { + PostId = 2, + BlogId = 2, + Title = "Around the World in Eighty Days", + Content = "consectetur adipiscing elit", + Rating = 5 + }, + new Post + { + PostId = 3, + BlogId = 2, + Title = "Glamping *is* the way", + Content = "sed do eiusmod tempor incididunt", + Rating = 4 + }, + new Post + { + PostId = 4, + BlogId = 2, + Title = "Travel in the time of pandemic", + Content = "ut labore et dolore magna aliqua", + Rating = 3 + }); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.RawSQL;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.RawSQL;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/RawSQL/Program.cs b/samples/core/Querying/RawSQL/Program.cs index ef0a0d4651..9972f53225 100644 --- a/samples/core/Querying/RawSQL/Program.cs +++ b/samples/core/Querying/RawSQL/Program.cs @@ -1,12 +1,12 @@ -using Microsoft.Data.SqlClient; +using System.Linq; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; -using System.Linq; namespace EFQuerying.RawSQL { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new BloggingContext()) { @@ -32,6 +32,18 @@ from [Post] as [p] return end"); + + context.Database.ExecuteSqlRaw( + @"create procedure [dbo].[GetMostPopularBlogs] as + begin + select * from dbo.Blogs order by Rating + end"); + + context.Database.ExecuteSqlRaw( + @"create procedure [dbo].[GetMostPopularBlogsForUser] @filterByUser nvarchar(max) as + begin + select * from dbo.Blogs order by Rating + end"); } using (var context = new BloggingContext()) diff --git a/samples/core/Querying/RawSQL/RawSQL.csproj b/samples/core/Querying/RawSQL/RawSQL.csproj index 0bbce76f3c..79b5d45fce 100644 --- a/samples/core/Querying/RawSQL/RawSQL.csproj +++ b/samples/core/Querying/RawSQL/RawSQL.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/RelatedData/BloggingContext.cs b/samples/core/Querying/RelatedData/BloggingContext.cs index 7a2e923719..9f5b20a0b0 100644 --- a/samples/core/Querying/RelatedData/BloggingContext.cs +++ b/samples/core/Querying/RelatedData/BloggingContext.cs @@ -26,15 +26,50 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasData( - new Blog { BlogId = 1, Url = @"https://devblogs.microsoft.com/dotnet", Rating = 5, OwnerId = 1, }, + new Blog + { + BlogId = 1, Url = @"https://devblogs.microsoft.com/dotnet", Rating = 5, OwnerId = 1, + }, new Blog { BlogId = 2, Url = @"https://mytravelblog.com/", Rating = 4, OwnerId = 3 }); modelBuilder.Entity() .HasData( - new Post { PostId = 1, BlogId = 1, Title = "What's new", Content = "Lorem ipsum dolor sit amet", Rating = 5, AuthorId = 1 }, - new Post { PostId = 2, BlogId = 2, Title = "Around the World in Eighty Days", Content = "consectetur adipiscing elit", Rating = 5, AuthorId = 2 }, - new Post { PostId = 3, BlogId = 2, Title = "Glamping *is* the way", Content = "sed do eiusmod tempor incididunt", Rating = 4, AuthorId = 3 }, - new Post { PostId = 4, BlogId = 2, Title = "Travel in the time of pandemic", Content = "ut labore et dolore magna aliqua", Rating = 3, AuthorId = 3 }); + new Post + { + PostId = 1, + BlogId = 1, + Title = "What's new", + Content = "Lorem ipsum dolor sit amet", + Rating = 5, + AuthorId = 1 + }, + new Post + { + PostId = 2, + BlogId = 2, + Title = "Around the World in Eighty Days", + Content = "consectetur adipiscing elit", + Rating = 5, + AuthorId = 2 + }, + new Post + { + PostId = 3, + BlogId = 2, + Title = "Glamping *is* the way", + Content = "sed do eiusmod tempor incididunt", + Rating = 4, + AuthorId = 3 + }, + new Post + { + PostId = 4, + BlogId = 2, + Title = "Travel in the time of pandemic", + Content = "ut labore et dolore magna aliqua", + Rating = 3, + AuthorId = 3 + }); modelBuilder.Entity() .HasData( @@ -67,7 +102,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.ComplexQuery;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.ComplexQuery;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/RelatedData/Program.cs b/samples/core/Querying/RelatedData/Program.cs index 8bca1e3f44..30e8393e9b 100644 --- a/samples/core/Querying/RelatedData/Program.cs +++ b/samples/core/Querying/RelatedData/Program.cs @@ -1,16 +1,18 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFQuerying.RelatedData { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { + using (var context = new BloggingContext()) + { + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + } + #region SingleInclude using (var context = new BloggingContext()) { @@ -25,11 +27,8 @@ static void Main(string[] args) { var blogs = context.Blogs .Include(blog => blog.Posts) - .Select(blog => new - { - Id = blog.BlogId, - Url = blog.Url - }) + .Select( + blog => new { Id = blog.BlogId, blog.Url }) .ToList(); } #endregion @@ -49,7 +48,7 @@ static void Main(string[] args) { var blogs = context.Blogs .Include(blog => blog.Posts) - .ThenInclude(post => post.Author) + .ThenInclude(post => post.Author) .ToList(); } #endregion @@ -59,8 +58,8 @@ static void Main(string[] args) { var blogs = context.Blogs .Include(blog => blog.Posts) - .ThenInclude(post => post.Author) - .ThenInclude(author => author.Photo) + .ThenInclude(post => post.Author) + .ThenInclude(author => author.Photo) .ToList(); } #endregion @@ -70,10 +69,10 @@ static void Main(string[] args) { var blogs = context.Blogs .Include(blog => blog.Posts) - .ThenInclude(post => post.Author) - .ThenInclude(author => author.Photo) + .ThenInclude(post => post.Author) + .ThenInclude(author => author.Photo) .Include(blog => blog.Owner) - .ThenInclude(owner => owner.Photo) + .ThenInclude(owner => owner.Photo) .ToList(); } #endregion @@ -83,9 +82,9 @@ static void Main(string[] args) { var blogs = context.Blogs .Include(blog => blog.Posts) - .ThenInclude(post => post.Author) + .ThenInclude(post => post.Author) .Include(blog => blog.Posts) - .ThenInclude(post => post.Tags) + .ThenInclude(post => post.Tags) .ToList(); } #endregion @@ -95,7 +94,7 @@ static void Main(string[] args) { var blogs = context.Blogs .Include(blog => blog.Owner.AuthoredPosts) - .ThenInclude(post => post.Blog.Owner.Photo) + .ThenInclude(post => post.Blog.Owner.Photo) .ToList(); } #endregion @@ -110,6 +109,12 @@ static void Main(string[] args) } #endregion + using (var context = new SplitQueriesBloggingContext()) + { + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + } + #region WithSplitQueryAsDefault using (var context = new SplitQueriesBloggingContext()) { @@ -176,10 +181,11 @@ static void Main(string[] args) using (var context = new BloggingContext()) { var filteredBlogs = context.Blogs - .Include(blog => blog.Posts - .Where(post => post.BlogId == 1) - .OrderByDescending(post => post.Title) - .Take(5)) + .Include( + blog => blog.Posts + .Where(post => post.BlogId == 1) + .OrderByDescending(post => post.Title) + .Take(5)) .ToList(); } #endregion @@ -189,9 +195,9 @@ static void Main(string[] args) { var filteredBlogs = context.Blogs .Include(blog => blog.Posts.Where(post => post.BlogId == 1)) - .ThenInclude(post => post.Author) + .ThenInclude(post => post.Author) .Include(blog => blog.Posts) - .ThenInclude(post => post.Tags.OrderBy(postTag => postTag.TagId).Skip(3)) + .ThenInclude(post => post.Tags.OrderBy(postTag => postTag.TagId).Skip(3)) .ToList(); } #endregion @@ -201,9 +207,9 @@ static void Main(string[] args) { var filteredBlogs = context.Blogs .Include(blog => blog.Posts.Where(post => post.BlogId == 1)) - .ThenInclude(post => post.Author) + .ThenInclude(post => post.Author) .Include(blog => blog.Posts.Where(post => post.BlogId == 1)) - .ThenInclude(post => post.Tags.OrderBy(postTag => postTag.TagId).Skip(3)) + .ThenInclude(post => post.Tags.OrderBy(postTag => postTag.TagId).Skip(3)) .ToList(); } #endregion diff --git a/samples/core/Querying/RelatedData/RelatedData.csproj b/samples/core/Querying/RelatedData/RelatedData.csproj index ef4a9d85f1..7d278785db 100644 --- a/samples/core/Querying/RelatedData/RelatedData.csproj +++ b/samples/core/Querying/RelatedData/RelatedData.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/Tags/Program.cs b/samples/core/Querying/Tags/Program.cs index 41707d018c..5e12a994aa 100644 --- a/samples/core/Querying/Tags/Program.cs +++ b/samples/core/Querying/Tags/Program.cs @@ -1,16 +1,12 @@ -using Microsoft.EntityFrameworkCore; +using System.Linq; +using Microsoft.EntityFrameworkCore; using NetTopologySuite.Geometries; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EFQuerying.Tags { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new SpatialContext()) { @@ -38,20 +34,20 @@ orderby f.Location.Distance(myLocation) descending using (var context = new SpatialContext()) { #region MultilineQueryTag -var results = Limit(GetNearestPeople(context, new Point(1, 2)), 25).TagWith( -@"This is a multi-line + var results = Limit(GetNearestPeople(context, new Point(1, 2)), 25).TagWith( + @"This is a multi-line string").ToList(); #endregion } } #region QueryableMethods - static IQueryable GetNearestPeople(SpatialContext context, Point myLocation) + private static IQueryable GetNearestPeople(SpatialContext context, Point myLocation) => from f in context.People.TagWith("GetNearestPeople") orderby f.Location.Distance(myLocation) descending select f; - static IQueryable Limit(IQueryable source, int limit) => source.TagWith("Limit").Take(limit); + private static IQueryable Limit(IQueryable source, int limit) => source.TagWith("Limit").Take(limit); #endregion } diff --git a/samples/core/Querying/Tags/SpatialContext.cs b/samples/core/Querying/Tags/SpatialContext.cs index afd99a3130..e7d9d9772f 100644 --- a/samples/core/Querying/Tags/SpatialContext.cs +++ b/samples/core/Querying/Tags/SpatialContext.cs @@ -9,20 +9,22 @@ public class SpatialContext : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(b => - { - b.Property(e => e.Location).HasColumnType("geometry"); + modelBuilder.Entity( + b => + { + b.Property(e => e.Location).HasColumnType("geometry"); - b.HasData( - new Person { Id = 1, Location = new Point(0, 1) }, - new Person { Id = 2, Location = new Point(2, 1) }, - new Person { Id = 3, Location = new Point(4, 5) }); - }); + b.HasData( + new Person { Id = 1, Location = new Point(0, 1) }, + new Person { Id = 2, Location = new Point(2, 1) }, + new Person { Id = 3, Location = new Point(4, 5) }); + }); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.Tags;Trusted_Connection=True;ConnectRetryCount=0", + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.Tags;Trusted_Connection=True;ConnectRetryCount=0", b => b.UseNetTopologySuite()); } } diff --git a/samples/core/Querying/Tags/Tags.csproj b/samples/core/Querying/Tags/Tags.csproj index 83cc8c52f3..ffe3337405 100644 --- a/samples/core/Querying/Tags/Tags.csproj +++ b/samples/core/Querying/Tags/Tags.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Querying/Tracking/BloggingContext.cs b/samples/core/Querying/Tracking/BloggingContext.cs index ff07924527..bfdece0b6a 100644 --- a/samples/core/Querying/Tracking/BloggingContext.cs +++ b/samples/core/Querying/Tracking/BloggingContext.cs @@ -16,7 +16,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.Tracking;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.Tracking;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/Tracking/Program.cs b/samples/core/Querying/Tracking/Program.cs index fde6b5e78a..181340ee22 100644 --- a/samples/core/Querying/Tracking/Program.cs +++ b/samples/core/Querying/Tracking/Program.cs @@ -1,15 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFQuerying.Tracking { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using (var context = new BloggingContext()) { @@ -65,12 +61,9 @@ static void Main(string[] args) { #region CustomProjection1 var blog = context.Blogs - .Select(b => - new - { - Blog = b, - PostCount = b.Posts.Count() - }); + .Select( + b => + new { Blog = b, PostCount = b.Posts.Count() }); #endregion } @@ -78,12 +71,9 @@ static void Main(string[] args) { #region CustomProjection2 var blog = context.Blogs - .Select(b => - new - { - Blog = b, - Post = b.Posts.OrderBy(p => p.Rating).LastOrDefault() - }); + .Select( + b => + new { Blog = b, Post = b.Posts.OrderBy(p => p.Rating).LastOrDefault() }); #endregion } @@ -91,12 +81,9 @@ static void Main(string[] args) { #region CustomProjection3 var blog = context.Blogs - .Select(b => - new - { - Id = b.BlogId, - Url = b.Url - }); + .Select( + b => + new { Id = b.BlogId, b.Url }); #endregion } @@ -105,11 +92,8 @@ static void Main(string[] args) #region ClientProjection var blogs = context.Blogs .OrderByDescending(blog => blog.Rating) - .Select(blog => new - { - Id = blog.BlogId, - Url = StandardizeUrl(blog) - }) + .Select( + blog => new { Id = blog.BlogId, Url = StandardizeUrl(blog) }) .ToList(); #endregion } diff --git a/samples/core/Querying/Tracking/Tracking.csproj b/samples/core/Querying/Tracking/Tracking.csproj index f7dec62699..a25ca425c0 100644 --- a/samples/core/Querying/Tracking/Tracking.csproj +++ b/samples/core/Querying/Tracking/Tracking.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Querying/UserDefinedFunctionMapping/Model.cs b/samples/core/Querying/UserDefinedFunctionMapping/Model.cs index 8338487f9c..2f24886098 100644 --- a/samples/core/Querying/UserDefinedFunctionMapping/Model.cs +++ b/samples/core/Querying/UserDefinedFunctionMapping/Model.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Storage; -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using Microsoft.EntityFrameworkCore.Storage; namespace EFQuerying.UserDefinedFunctionMapping { @@ -65,10 +65,10 @@ public IQueryable PostsWithPopularComments(int likeThreshold) #region NullabilityPropagationFunctionDefinition public string ConcatStrings(string prm1, string prm2) - => throw new System.InvalidOperationException(); + => throw new InvalidOperationException(); public string ConcatStringsOptimized(string prm1, string prm2) - => throw new System.InvalidOperationException(); + => throw new InvalidOperationException(); #endregion protected override void OnModelCreating(ModelBuilder modelBuilder) @@ -90,15 +90,49 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasData( - new Post { PostId = 1, BlogId = 1, Title = "What's new", Content = "Lorem ipsum dolor sit amet", Rating = 5 }, - new Post { PostId = 2, BlogId = 2, Title = "Around the World in Eighty Days", Content = "consectetur adipiscing elit", Rating = 5 }, - new Post { PostId = 3, BlogId = 2, Title = "Glamping *is* the way", Content = "sed do eiusmod tempor incididunt", Rating = 4 }, - new Post { PostId = 4, BlogId = 2, Title = "Travel in the time of pandemic", Content = "ut labore et dolore magna aliqua", Rating = 3 }); + new Post + { + PostId = 1, + BlogId = 1, + Title = "What's new", + Content = "Lorem ipsum dolor sit amet", + Rating = 5 + }, + new Post + { + PostId = 2, + BlogId = 2, + Title = "Around the World in Eighty Days", + Content = "consectetur adipiscing elit", + Rating = 5 + }, + new Post + { + PostId = 3, + BlogId = 2, + Title = "Glamping *is* the way", + Content = "sed do eiusmod tempor incididunt", + Rating = 4 + }, + new Post + { + PostId = 4, + BlogId = 2, + Title = "Travel in the time of pandemic", + Content = "ut labore et dolore magna aliqua", + Rating = 3 + }); modelBuilder.Entity() .HasData( new Comment { CommentId = 1, PostId = 1, Text = "Exciting!", Likes = 3 }, - new Comment { CommentId = 2, PostId = 1, Text = "Dotnet is useless - why use C# when you can write super fast assembly code instead?", Likes = 0 }, + new Comment + { + CommentId = 2, + PostId = 1, + Text = "Dotnet is useless - why use C# when you can write super fast assembly code instead?", + Likes = 0 + }, new Comment { CommentId = 3, PostId = 2, Text = "Didn't think you would make it!", Likes = 3 }, new Comment { CommentId = 4, PostId = 2, Text = "Are you going to try 70 days next time?", Likes = 5 }, new Comment { CommentId = 5, PostId = 2, Text = "Good thing the earth is round :)", Likes = 5 }, @@ -111,47 +145,49 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) #region HasTranslationFunctionConfiguration // 100 * ABS(first - second) / ((first + second) / 2) - modelBuilder.HasDbFunction(typeof(BloggingContext).GetMethod(nameof(PercentageDifference), new[] { typeof(double), typeof(int) })) - .HasTranslation(args => - new SqlBinaryExpression( - ExpressionType.Multiply, - new SqlConstantExpression( - Expression.Constant(100), - new IntTypeMapping("int", DbType.Int32)), + modelBuilder.HasDbFunction( + typeof(BloggingContext).GetMethod(nameof(PercentageDifference), new[] { typeof(double), typeof(int) })) + .HasTranslation( + args => new SqlBinaryExpression( - ExpressionType.Divide, - new SqlFunctionExpression( - "ABS", - new SqlExpression[] - { + ExpressionType.Multiply, + new SqlConstantExpression( + Expression.Constant(100), + new IntTypeMapping("int", DbType.Int32)), + new SqlBinaryExpression( + ExpressionType.Divide, + new SqlFunctionExpression( + "ABS", + new SqlExpression[] + { + new SqlBinaryExpression( + ExpressionType.Subtract, + args.First(), + args.Skip(1).First(), + args.First().Type, + args.First().TypeMapping) + }, + nullable: true, + argumentsPropagateNullability: new[] { true, true }, + type: args.First().Type, + typeMapping: args.First().TypeMapping), + new SqlBinaryExpression( + ExpressionType.Divide, new SqlBinaryExpression( - ExpressionType.Subtract, + ExpressionType.Add, args.First(), args.Skip(1).First(), args.First().Type, - args.First().TypeMapping) - }, - nullable: true, - argumentsPropagateNullability: new[] { true, true }, - type: args.First().Type, - typeMapping: args.First().TypeMapping), - new SqlBinaryExpression( - ExpressionType.Divide, - new SqlBinaryExpression( - ExpressionType.Add, - args.First(), - args.Skip(1).First(), + args.First().TypeMapping), + new SqlConstantExpression( + Expression.Constant(2), + new IntTypeMapping("int", DbType.Int32)), args.First().Type, args.First().TypeMapping), - new SqlConstantExpression( - Expression.Constant(2), - new IntTypeMapping("int", DbType.Int32)), args.First().Type, args.First().TypeMapping), args.First().Type, - args.First().TypeMapping), - args.First().Type, - args.First().TypeMapping)); + args.First().TypeMapping)); #endregion #region NullabilityPropagationModelConfiguration @@ -177,7 +213,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying.UserDefinedFunctionMapping;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFQuerying.UserDefinedFunctionMapping;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Querying/UserDefinedFunctionMapping/Program.cs b/samples/core/Querying/UserDefinedFunctionMapping/Program.cs index ad93d57916..4c3f0b96c1 100644 --- a/samples/core/Querying/UserDefinedFunctionMapping/Program.cs +++ b/samples/core/Querying/UserDefinedFunctionMapping/Program.cs @@ -1,11 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using System.Linq; +using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFQuerying.UserDefinedFunctionMapping { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { using var context = new BloggingContext(); context.Database.EnsureDeleted(); @@ -56,12 +56,13 @@ where context.ActivePostCountForBlog(b.BlogId) > 1 #region HasTranslationQuery var query2 = from p in context.Posts select context.PercentageDifference(p.BlogId, 3); - #endregion + #endregion var result2 = query2.ToList(); #region NullabilityPropagationExamples var query3 = context.Blogs.Where(e => context.ConcatStrings(e.Url, e.Rating.ToString()) != "https://mytravelblog.com/4"); - var query4 = context.Blogs.Where(e => context.ConcatStringsOptimized(e.Url, e.Rating.ToString()) != "https://mytravelblog.com/4"); + var query4 = context.Blogs.Where( + e => context.ConcatStringsOptimized(e.Url, e.Rating.ToString()) != "https://mytravelblog.com/4"); #endregion var result3 = query3.ToList(); diff --git a/samples/core/Querying/UserDefinedFunctionMapping/UserDefinedFunctionMapping.csproj b/samples/core/Querying/UserDefinedFunctionMapping/UserDefinedFunctionMapping.csproj index 9b650bb7a7..9adb88c01f 100644 --- a/samples/core/Querying/UserDefinedFunctionMapping/UserDefinedFunctionMapping.csproj +++ b/samples/core/Querying/UserDefinedFunctionMapping/UserDefinedFunctionMapping.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/core/Samples.sln.DotSettings b/samples/core/Samples.sln.DotSettings index 08fc1d48b3..9d20d8f501 100644 --- a/samples/core/Samples.sln.DotSettings +++ b/samples/core/Samples.sln.DotSettings @@ -93,9 +93,7 @@ True - Copyright (c) .NET Foundation. All rights reserved. -Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - + True True True diff --git a/samples/core/Saving/Basics/BloggingContext.cs b/samples/core/Saving/Basics/BloggingContext.cs index 46c1626244..82fa2e331b 100644 --- a/samples/core/Saving/Basics/BloggingContext.cs +++ b/samples/core/Saving/Basics/BloggingContext.cs @@ -9,7 +9,8 @@ public class BloggingContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFSaving.Basics;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Basics;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Saving/Basics/Sample.cs b/samples/core/Saving/Basics/Sample.cs index ecd8bac004..fb62139f0f 100644 --- a/samples/core/Saving/Basics/Sample.cs +++ b/samples/core/Saving/Basics/Sample.cs @@ -59,7 +59,7 @@ public static void Run() firstBlog.Url = ""; // remove - var lastBlog = context.Blogs.Last(); + var lastBlog = context.Blogs.OrderBy(e => e.BlogId).Last(); context.Blogs.Remove(lastBlog); context.SaveChanges(); diff --git a/samples/core/Saving/CascadeDelete/BloggingContext.cs b/samples/core/Saving/CascadeDelete/BloggingContext.cs index 803695bba9..7a1236c193 100644 --- a/samples/core/Saving/CascadeDelete/BloggingContext.cs +++ b/samples/core/Saving/CascadeDelete/BloggingContext.cs @@ -66,13 +66,16 @@ private class MyLoggerProvider : ILoggerProvider { public ILogger CreateLogger(string categoryName) => new SampleLogger(); - public void Dispose() { } + public void Dispose() + { + } private class SampleLogger : ILogger { public bool IsEnabled(LogLevel logLevel) => true; - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, + public void Log( + LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { if (eventId.Id == RelationalEventId.CommandExecuting.Id) @@ -81,7 +84,8 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except var commandIndex = Math.Max(message.IndexOf("UPDATE"), message.IndexOf("DELETE")); if (commandIndex >= 0) { - var truncatedMessage = message.Substring(commandIndex, message.IndexOf(";", commandIndex) - commandIndex).Replace(Environment.NewLine, " "); + var truncatedMessage = message.Substring(commandIndex, message.IndexOf(";", commandIndex) - commandIndex) + .Replace(Environment.NewLine, " "); for (var i = 0; i < 4; i++) { diff --git a/samples/core/Saving/CascadeDelete/Sample.cs b/samples/core/Saving/CascadeDelete/Sample.cs index 9c1d659330..2ddc588334 100644 --- a/samples/core/Saving/CascadeDelete/Sample.cs +++ b/samples/core/Saving/CascadeDelete/Sample.cs @@ -1,7 +1,7 @@ using System; -using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFSaving.CascadeDelete { @@ -32,7 +32,8 @@ public static void Run() private static void DeleteBehaviorSample(DeleteBehavior deleteBehavior, bool requiredRelationship) { - Console.WriteLine($"Test using DeleteBehavior.{deleteBehavior} with {(requiredRelationship ? "required" : "optional")} relationship:"); + Console.WriteLine( + $"Test using DeleteBehavior.{deleteBehavior} with {(requiredRelationship ? "required" : "optional")} relationship:"); InitializeDatabase(requiredRelationship); @@ -64,7 +65,8 @@ private static void DeleteBehaviorSample(DeleteBehavior deleteBehavior, bool req DumpSql(); Console.WriteLine(); - Console.WriteLine($" SaveChanges threw {e.GetType().Name}: {(e is DbUpdateException ? e.InnerException.Message : e.Message)}"); + Console.WriteLine( + $" SaveChanges threw {e.GetType().Name}: {(e is DbUpdateException ? e.InnerException.Message : e.Message)}"); } #endregion @@ -73,7 +75,8 @@ private static void DeleteBehaviorSample(DeleteBehavior deleteBehavior, bool req private static void DeleteOrphansSample(DeleteBehavior deleteBehavior, bool requiredRelationship) { - Console.WriteLine($"Test deleting orphans with DeleteBehavior.{deleteBehavior} and {(requiredRelationship ? "a required" : "an optional")} relationship:"); + Console.WriteLine( + $"Test deleting orphans with DeleteBehavior.{deleteBehavior} and {(requiredRelationship ? "a required" : "an optional")} relationship:"); InitializeDatabase(requiredRelationship); @@ -105,7 +108,8 @@ private static void DeleteOrphansSample(DeleteBehavior deleteBehavior, bool requ DumpSql(); Console.WriteLine(); - Console.WriteLine($" SaveChanges threw {e.GetType().Name}: {(e is DbUpdateException ? e.InnerException.Message : e.Message)}"); + Console.WriteLine( + $" SaveChanges threw {e.GetType().Name}: {(e is DbUpdateException ? e.InnerException.Message : e.Message)}"); } #endregion @@ -118,15 +122,12 @@ private static void InitializeDatabase(bool requiredRelationship) context.Database.EnsureDeleted(); context.Database.EnsureCreated(); - context.Blogs.Add(new Blog - { - Url = "http://sample.com", - Posts = new List + context.Blogs.Add( + new Blog { - new Post {Title = "Saving Data with EF"}, - new Post {Title = "Cascade Delete with EF"} - } - }); + Url = "http://sample.com", + Posts = new List { new Post { Title = "Saving Data with EF" }, new Post { Title = "Cascade Delete with EF" } } + }); context.SaveChanges(); } @@ -146,7 +147,7 @@ private static void DumpEntities(string message, BloggingContext context, Blog b Console.WriteLine( $" Post '{post.PostId}' is in state {postEntry.State} " + - $"with FK '{post.BlogId?.ToString() ?? "null"}' and {(post.Blog == null ? "no reference to a blog." : $"reference to blog '{post.BlogId}'." )}"); + $"with FK '{post.BlogId?.ToString() ?? "null"}' and {(post.Blog == null ? "no reference to a blog." : $"reference to blog '{post.BlogId}'.")}"); } } diff --git a/samples/core/Saving/Disconnected/BloggingContext.cs b/samples/core/Saving/Disconnected/BloggingContext.cs index 7bdb3cbc3e..dbbbefd531 100644 --- a/samples/core/Saving/Disconnected/BloggingContext.cs +++ b/samples/core/Saving/Disconnected/BloggingContext.cs @@ -9,7 +9,8 @@ public class BloggingContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFSaving.Disconnected;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Disconnected;Trusted_Connection=True;ConnectRetryCount=0"); } } } diff --git a/samples/core/Saving/Disconnected/EntityBase.cs b/samples/core/Saving/Disconnected/EntityBase.cs index 49b350541f..48d633bae4 100644 --- a/samples/core/Saving/Disconnected/EntityBase.cs +++ b/samples/core/Saving/Disconnected/EntityBase.cs @@ -13,4 +13,4 @@ public abstract class EntityBase [NotMapped] public bool IsChanged { get; set; } } -} \ No newline at end of file +} diff --git a/samples/core/Saving/Disconnected/Sample.cs b/samples/core/Saving/Disconnected/Sample.cs index 17a4f9c59e..2911b0b548 100644 --- a/samples/core/Saving/Disconnected/Sample.cs +++ b/samples/core/Saving/Disconnected/Sample.cs @@ -32,7 +32,7 @@ private static void IsItNew() Console.WriteLine("Show entity-specific check for key set:"); using (var context = new BloggingContext()) { - var blog = new Blog {Url = "http://sample.com"}; + var blog = new Blog { Url = "http://sample.com" }; // Key is not set for a new entity Console.WriteLine($" Blog entity is {(IsItNew(blog) ? "new" : "existing")}."); @@ -48,7 +48,7 @@ private static void IsItNew() Console.WriteLine("Show general IsKeySet:"); using (var context = new BloggingContext()) { - var blog = new Blog {Url = "http://sample.com"}; + var blog = new Blog { Url = "http://sample.com" }; // Key is not set for a new entity Console.WriteLine($" Blog entity is {(IsItNew(context, (object)blog) ? "new" : "existing")}."); @@ -64,7 +64,7 @@ private static void IsItNew() Console.WriteLine("Show key set on Add:"); using (var context = new BloggingContext()) { - var blog = new Blog {Url = "http://sample.com"}; + var blog = new Blog { Url = "http://sample.com" }; // Key is not set for a new entity Console.WriteLine($" Blog entity is {(IsItNew(context, (object)blog) ? "new" : "existing")}."); @@ -79,7 +79,7 @@ private static void IsItNew() Console.WriteLine("Show using query to check for new entity:"); using (var context = new BloggingContext()) { - var blog = new Blog {Url = "http://sample.com"}; + var blog = new Blog { Url = "http://sample.com" }; Console.WriteLine($" Blog entity is {(IsItNew(context, blog) ? "new" : "existing")}."); @@ -427,12 +427,7 @@ private static Blog CreateBlogAndPosts() #region CreateBlogAndPosts var blog = new Blog { - Url = "http://sample.com", - Posts = new List - { - new Post {Title = "Post 1"}, - new Post {Title = "Post 2"}, - } + Url = "http://sample.com", Posts = new List { new Post { Title = "Post 1" }, new Post { Title = "Post 2" }, } }; #endregion diff --git a/samples/core/Saving/Program.cs b/samples/core/Saving/Program.cs index a32d291e6c..aed3a65392 100644 --- a/samples/core/Saving/Program.cs +++ b/samples/core/Saving/Program.cs @@ -1,17 +1,20 @@ -namespace EFSaving +using EFSaving.Basics; +using EFSaving.Transactions; + +namespace EFSaving { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { - Basics.Sample.Run(); + Sample.Run(); RelatedData.Sample.Run(); CascadeDelete.Sample.Run(); Concurrency.Sample.Run(); - Transactions.ControllingTransaction.Run(); - Transactions.ManagingSavepoints.Run(); - Transactions.SharingTransaction.Run(); - Transactions.ExternalDbTransaction.Run(); + ControllingTransaction.Run(); + ManagingSavepoints.Run(); + SharingTransaction.Run(); + ExternalDbTransaction.Run(); Disconnected.Sample.Run(); } } diff --git a/samples/core/Saving/RelatedData/Sample.cs b/samples/core/Saving/RelatedData/Sample.cs index 7023dd299b..0c29ca48f4 100644 --- a/samples/core/Saving/RelatedData/Sample.cs +++ b/samples/core/Saving/RelatedData/Sample.cs @@ -1,6 +1,6 @@ -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFSaving.RelatedData { @@ -74,7 +74,8 @@ public class BloggingContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFSaving.RelatedData;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.RelatedData;Trusted_Connection=True;ConnectRetryCount=0"); } } diff --git a/samples/core/Saving/Saving.csproj b/samples/core/Saving/Saving.csproj index 3cf638d7c0..d948bbbafe 100644 --- a/samples/core/Saving/Saving.csproj +++ b/samples/core/Saving/Saving.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/core/Saving/Transactions/AmbientTransaction.cs b/samples/core/Saving/Transactions/AmbientTransaction.cs index 80cf64177d..45dbb972cc 100644 --- a/samples/core/Saving/Transactions/AmbientTransaction.cs +++ b/samples/core/Saving/Transactions/AmbientTransaction.cs @@ -1,6 +1,7 @@ +using System; using System.Transactions; -using Microsoft.EntityFrameworkCore; using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; namespace EFSaving.Transactions { @@ -8,7 +9,8 @@ public class AmbientTransaction { public static void Run() { - var connectionString = @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; + var connectionString = + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; using (var context = new BloggingContext( new DbContextOptionsBuilder() @@ -49,7 +51,7 @@ public static void Run() // when disposed if either commands fails scope.Complete(); } - catch (System.Exception) + catch (Exception) { // TODO: Handle failure } @@ -61,12 +63,12 @@ public class BloggingContext : DbContext { public BloggingContext(DbContextOptions options) : base(options) - { } + { + } public DbSet Blogs { get; set; } } - public class Blog { public int BlogId { get; set; } diff --git a/samples/core/Saving/Transactions/CommitableTransaction.cs b/samples/core/Saving/Transactions/CommitableTransaction.cs index 8b5c7fba24..8d58daf31a 100644 --- a/samples/core/Saving/Transactions/CommitableTransaction.cs +++ b/samples/core/Saving/Transactions/CommitableTransaction.cs @@ -1,6 +1,7 @@ +using System; using System.Transactions; -using Microsoft.EntityFrameworkCore; using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; namespace EFSaving.Transactions { @@ -8,7 +9,8 @@ public class CommitableTransaction { public static void Run() { - var connectionString = @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; + var connectionString = + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; using (var context = new BloggingContext( new DbContextOptionsBuilder() @@ -51,7 +53,7 @@ public static void Run() // when disposed if either commands fails transaction.Commit(); } - catch (System.Exception) + catch (Exception) { // TODO: Handle failure } @@ -63,12 +65,12 @@ public class BloggingContext : DbContext { public BloggingContext(DbContextOptions options) : base(options) - { } + { + } public DbSet Blogs { get; set; } } - public class Blog { public int BlogId { get; set; } diff --git a/samples/core/Saving/Transactions/ControllingTransaction.cs b/samples/core/Saving/Transactions/ControllingTransaction.cs index 0a716346fc..ba03895c93 100644 --- a/samples/core/Saving/Transactions/ControllingTransaction.cs +++ b/samples/core/Saving/Transactions/ControllingTransaction.cs @@ -1,6 +1,6 @@ -using Microsoft.EntityFrameworkCore; using System; using System.Linq; +using Microsoft.EntityFrameworkCore; namespace EFSaving.Transactions { @@ -47,7 +47,8 @@ public class BloggingContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"); } } diff --git a/samples/core/Saving/Transactions/ExternalDbTransaction.cs b/samples/core/Saving/Transactions/ExternalDbTransaction.cs index 2f1a98204f..04086b458b 100644 --- a/samples/core/Saving/Transactions/ExternalDbTransaction.cs +++ b/samples/core/Saving/Transactions/ExternalDbTransaction.cs @@ -1,5 +1,6 @@ -using Microsoft.EntityFrameworkCore; +using System; using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; namespace EFSaving.Transactions { @@ -7,7 +8,8 @@ public class ExternalDbTransaction { public static void Run() { - var connectionString = @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; + var connectionString = + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; using (var context = new BloggingContext( new DbContextOptionsBuilder() @@ -47,7 +49,7 @@ public static void Run() // when disposed if either commands fails transaction.Commit(); } - catch (System.Exception) + catch (Exception) { // TODO: Handle failure } @@ -58,12 +60,12 @@ public class BloggingContext : DbContext { public BloggingContext(DbContextOptions options) : base(options) - { } + { + } public DbSet Blogs { get; set; } } - public class Blog { public int BlogId { get; set; } diff --git a/samples/core/Saving/Transactions/ManagingSavepoints.cs b/samples/core/Saving/Transactions/ManagingSavepoints.cs index 9a166788f0..44a6dcb578 100644 --- a/samples/core/Saving/Transactions/ManagingSavepoints.cs +++ b/samples/core/Saving/Transactions/ManagingSavepoints.cs @@ -1,5 +1,5 @@ -using Microsoft.EntityFrameworkCore; using System; +using Microsoft.EntityFrameworkCore; namespace EFSaving.Transactions { @@ -46,7 +46,8 @@ public class BloggingContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"); + optionsBuilder.UseSqlServer( + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"); } } diff --git a/samples/core/Saving/Transactions/SharingTransaction.cs b/samples/core/Saving/Transactions/SharingTransaction.cs index 7813843110..ff4581ee82 100644 --- a/samples/core/Saving/Transactions/SharingTransaction.cs +++ b/samples/core/Saving/Transactions/SharingTransaction.cs @@ -1,8 +1,8 @@ using System; using System.Linq; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.Data.SqlClient; namespace EFSaving.Transactions { @@ -10,7 +10,8 @@ public class SharingTransaction { public static void Run() { - var connectionString = @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; + var connectionString = + @"Server=(localdb)\mssqllocaldb;Database=EFSaving.Transactions;Trusted_Connection=True;ConnectRetryCount=0"; using (var context = new BloggingContext( new DbContextOptionsBuilder() @@ -59,7 +60,8 @@ public class BloggingContext : DbContext { public BloggingContext(DbContextOptions options) : base(options) - { } + { + } public DbSet Blogs { get; set; } } diff --git a/samples/core/Schemas/Migrations/CustomOperation.cs b/samples/core/Schemas/Migrations/CustomOperation.cs index d85b9a4b51..3c39b0d2d4 100644 --- a/samples/core/Schemas/Migrations/CustomOperation.cs +++ b/samples/core/Schemas/Migrations/CustomOperation.cs @@ -5,26 +5,22 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; #region snippet_CreateUserOperation -class CreateUserOperation : MigrationOperation +internal class CreateUserOperation : MigrationOperation { public string Name { get; set; } public string Password { get; set; } } #endregion -static class MigrationBuilderExtensions +internal static class MigrationBuilderExtensions { #region snippet_MigrationBuilderExtension - static OperationBuilder CreateUser( + private static OperationBuilder CreateUser( this MigrationBuilder migrationBuilder, string name, string password) { - var operation = new CreateUserOperation - { - Name = name, - Password = password - }; + var operation = new CreateUserOperation { Name = name, Password = password }; migrationBuilder.Operations.Add(operation); return new OperationBuilder(operation); @@ -33,11 +29,11 @@ static OperationBuilder CreateUser( } #region snippet_MigrationsSqlGenerator -class MyMigrationsSqlGenerator : SqlServerMigrationsSqlGenerator +internal class MyMigrationsSqlGenerator : SqlServerMigrationsSqlGenerator { public MyMigrationsSqlGenerator( MigrationsSqlGeneratorDependencies dependencies, - IMigrationsAnnotationProvider migrationsAnnotations) + IRelationalAnnotationProvider migrationsAnnotations) : base(dependencies, migrationsAnnotations) { } @@ -75,9 +71,9 @@ private void Generate( } #endregion -class CustomOperationContext : DbContext +internal class CustomOperationContext : DbContext { - readonly string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Sample"; + private readonly string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Sample"; #region snippet_OnConfiguring protected override void OnConfiguring(DbContextOptionsBuilder options) @@ -85,4 +81,4 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) .UseSqlServer(_connectionString) .ReplaceService(); #endregion -} \ No newline at end of file +} diff --git a/samples/core/Schemas/Migrations/CustomOperationMultiSql.cs b/samples/core/Schemas/Migrations/CustomOperationMultiSql.cs index d57e274378..a1e4efd056 100644 --- a/samples/core/Schemas/Migrations/CustomOperationMultiSql.cs +++ b/samples/core/Schemas/Migrations/CustomOperationMultiSql.cs @@ -3,10 +3,10 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; -static class MultiSqlMigrationBuilderExtensions +internal static class MultiSqlMigrationBuilderExtensions { #region snippet_CustomOperationMultiSql - static OperationBuilder CreateUser( + private static OperationBuilder CreateUser( this MigrationBuilder migrationBuilder, string name, string password) diff --git a/samples/core/Schemas/Migrations/CustomOperationSql.cs b/samples/core/Schemas/Migrations/CustomOperationSql.cs index ab0d3cca83..9f6b5e9ea6 100644 --- a/samples/core/Schemas/Migrations/CustomOperationSql.cs +++ b/samples/core/Schemas/Migrations/CustomOperationSql.cs @@ -2,13 +2,13 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; -static class SqlMigrationBuilderExtensions +internal static class SqlMigrationBuilderExtensions { #region snippet_CustomOperationSql - static OperationBuilder CreateUser( + private static OperationBuilder CreateUser( this MigrationBuilder migrationBuilder, string name, string password) => migrationBuilder.Sql($"CREATE USER {name} WITH PASSWORD '{password}';"); #endregion -} \ No newline at end of file +} diff --git a/samples/core/Schemas/Migrations/MigrationTableNameContext.cs b/samples/core/Schemas/Migrations/MigrationTableNameContext.cs index 3e7bdcbb91..8512c0d4fd 100644 --- a/samples/core/Schemas/Migrations/MigrationTableNameContext.cs +++ b/samples/core/Schemas/Migrations/MigrationTableNameContext.cs @@ -4,7 +4,7 @@ namespace Migrations { public class MigrationTableNameContext : DbContext { - readonly string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Sample"; + private readonly string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Sample"; #region TableNameContext protected override void OnConfiguring(DbContextOptionsBuilder options) diff --git a/samples/core/Schemas/Migrations/Migrations.csproj b/samples/core/Schemas/Migrations/Migrations.csproj index 3fa6d51da8..8570f7576e 100644 --- a/samples/core/Schemas/Migrations/Migrations.csproj +++ b/samples/core/Schemas/Migrations/Migrations.csproj @@ -5,7 +5,7 @@ - + diff --git a/samples/core/Schemas/Migrations/MyHistoryRepository.cs b/samples/core/Schemas/Migrations/MyHistoryRepository.cs index f04d6867c0..568f73e3d0 100644 --- a/samples/core/Schemas/Migrations/MyHistoryRepository.cs +++ b/samples/core/Schemas/Migrations/MyHistoryRepository.cs @@ -9,7 +9,7 @@ namespace Migrations { public class MyHistoryRepositoryContext : DbContext { - readonly string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Sample"; + private readonly string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Sample"; #region HistoryRepositoryContext protected override void OnConfiguring(DbContextOptionsBuilder options) @@ -20,7 +20,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) } #region HistoryRepository - class MyHistoryRepository : SqlServerHistoryRepository + internal class MyHistoryRepository : SqlServerHistoryRepository { public MyHistoryRepository(HistoryRepositoryDependencies dependencies) : base(dependencies) diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/ApplicationDbContext.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/ApplicationDbContext.cs index f901a61c63..25694de5b3 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/ApplicationDbContext.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/ApplicationDbContext.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace WebApplication1.Data diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/WebApplication1.Data.csproj b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/WebApplication1.Data.csproj index 2316561426..9b5ee78b2c 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/WebApplication1.Data.csproj +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Data/WebApplication1.Data.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/00000000000000_CreateIdentitySchema.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/00000000000000_CreateIdentitySchema.cs index 4f191adf61..b838d47bd3 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/00000000000000_CreateIdentitySchema.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/00000000000000_CreateIdentitySchema.cs @@ -17,10 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder) NormalizedName = table.Column(maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(nullable: true) }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); + constraints: table => { table.PrimaryKey("PK_AspNetRoles", x => x.Id); }); migrationBuilder.CreateTable( name: "AspNetUsers", @@ -42,10 +39,7 @@ protected override void Up(MigrationBuilder migrationBuilder) LockoutEnabled = table.Column(nullable: false), AccessFailedCount = table.Column(nullable: false) }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); + constraints: table => { table.PrimaryKey("PK_AspNetUsers", x => x.Id); }); migrationBuilder.CreateTable( name: "AspNetRoleClaims", @@ -111,11 +105,7 @@ protected override void Up(MigrationBuilder migrationBuilder) migrationBuilder.CreateTable( name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(nullable: false), - RoleId = table.Column(nullable: false) - }, + columns: table => new { UserId = table.Column(nullable: false), RoleId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/ApplicationDbContextModelSnapshot.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/ApplicationDbContextModelSnapshot.cs index 2ede466fea..60817cd5d2 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/ApplicationDbContextModelSnapshot.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1.Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,15 +1,13 @@ -// using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using WebApplication1.Data; namespace WebApplication1.Migrations { [DbContext(typeof(ApplicationDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot + internal class ApplicationDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -19,7 +17,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") .HasColumnType("nvarchar(450)"); @@ -46,7 +45,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetRoles"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -70,7 +70,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetRoleClaims"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") .HasColumnType("nvarchar(450)"); @@ -135,7 +136,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetUsers"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -159,7 +161,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetUserClaims"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasColumnType("nvarchar(128)") @@ -183,7 +186,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetUserLogins"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") .HasColumnType("nvarchar(450)"); @@ -198,7 +202,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetUserRoles"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") .HasColumnType("nvarchar(450)"); @@ -219,7 +224,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetUserTokens"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() @@ -228,7 +234,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() @@ -237,7 +244,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() @@ -246,7 +254,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() @@ -261,7 +270,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + modelBuilder.Entity( + "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Areas/Identity/Pages/_ViewStart.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Areas/Identity/Pages/_ViewStart.cshtml index 7bd9b6bb87..4db7508a0e 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Areas/Identity/Pages/_ViewStart.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Areas/Identity/Pages/_ViewStart.cshtml @@ -1,3 +1,3 @@ @{ Layout = "/Pages/Shared/_Layout.cshtml"; -} +} \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml index 6f92b95655..b5105b6de1 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml @@ -23,4 +23,4 @@ It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app. -

+

\ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml.cs index 8f63aaba46..c5b54c8dcb 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Error.cshtml.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml index b5f0c15fce..fd28464cc7 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml @@ -7,4 +7,4 @@

Welcome

Learn about building Web apps with ASP.NET Core.

-
+ \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml.cs index eea1de4664..ababc417c5 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Index.cshtml.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; namespace WebApplication1.Pages @@ -19,7 +14,6 @@ public IndexModel(ILogger logger) public void OnGet() { - } } } diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml index 46ba96612e..a92998a633 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml @@ -5,4 +5,4 @@ }

@ViewData["Title"]

-

Use this page to detail your site's privacy policy.

+

Use this page to detail your site's privacy policy.

\ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml.cs index 21019e5e49..37dbe33d4d 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Privacy.cshtml.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; namespace WebApplication1.Pages diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_Layout.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_Layout.cshtml index 1cac9d142a..9d6c673d53 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_Layout.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_Layout.cshtml @@ -1,51 +1,51 @@  - - + + @ViewData["Title"] - WebApplication1 - - + + -
- +
+
+
+ @RenderBody() +
+
+ +
-
- @RenderBody() -
+ © 2020 - WebApplication1 - Privacy
+
-
-
- © 2020 - WebApplication1 - Privacy -
-
- - - - + + + - @RenderSection("Scripts", required: false) +@RenderSection("Scripts", required: false) - + \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_LoginPartial.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_LoginPartial.cshtml index c45b365fd4..e85ec77721 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_LoginPartial.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_LoginPartial.cshtml @@ -1,26 +1,25 @@ -@using Microsoft.AspNetCore.Identity -@inject SignInManager SignInManager +@inject SignInManager SignInManager @inject UserManager UserManager + @if (SignInManager.IsSignedIn(User)) + { + + + } + else + { + + + } + \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_ValidationScriptsPartial.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_ValidationScriptsPartial.cshtml index 5a16d80a9a..660f00c3bb 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_ValidationScriptsPartial.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -1,2 +1,2 @@  - + \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewImports.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewImports.cshtml index 3ee522ca54..83237e879d 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewImports.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewImports.cshtml @@ -2,4 +2,4 @@ @using WebApplication1 @using WebApplication1.Data @namespace WebApplication1.Pages -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewStart.cshtml b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewStart.cshtml index a5f10045db..1af6e49466 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewStart.cshtml +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Pages/_ViewStart.cshtml @@ -1,3 +1,3 @@ @{ Layout = "_Layout"; -} +} \ No newline at end of file diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Program.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Program.cs index c015cb72dc..4909a7b09e 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Program.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Program.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; namespace WebApplication1 { @@ -18,9 +12,6 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); } } diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Startup.cs b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Startup.cs index 915438f187..1681493893 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Startup.cs +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/Startup.cs @@ -22,14 +22,16 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { #region snippet_MigrationsAssembly - services.AddDbContext(options => - options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"), - x => x.MigrationsAssembly("WebApplication1.Migrations"))); + services.AddDbContext( + options => + options.UseSqlServer( + Configuration.GetConnectionString("DefaultConnection"), + x => x.MigrationsAssembly("WebApplication1.Migrations"))); #endregion services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores(); services.AddRazorPages(); + services.AddDatabaseDeveloperPageExceptionFilter(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -38,7 +40,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseDatabaseErrorPage(); + app.UseMigrationsEndPoint(); } else { @@ -55,10 +57,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseAuthentication(); app.UseAuthorization(); - app.UseEndpoints(endpoints => - { - endpoints.MapRazorPages(); - }); + app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } } } diff --git a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/WebApplication1.csproj b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/WebApplication1.csproj index 7413799f6e..8671a00675 100644 --- a/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/WebApplication1.csproj +++ b/samples/core/Schemas/ThreeProjectMigrations/WebApplication1/WebApplication1.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/20200915225801_InitialCreate.cs b/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/20200915225801_InitialCreate.cs index b6d31bded4..9e1f5ecf71 100644 --- a/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/20200915225801_InitialCreate.cs +++ b/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/20200915225801_InitialCreate.cs @@ -15,10 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Source = table.Column(type: "nvarchar(max)", nullable: true), Title = table.Column(type: "nvarchar(max)", nullable: true) }, - constraints: table => - { - table.PrimaryKey("PK_Blogs", x => x.Id); - }); + constraints: table => { table.PrimaryKey("PK_Blogs", x => x.Id); }); migrationBuilder.CreateTable( name: "People", @@ -29,10 +26,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Name = table.Column(type: "nvarchar(max)", nullable: true), Email = table.Column(type: "nvarchar(450)", nullable: true) }, - constraints: table => - { - table.PrimaryKey("PK_People", x => x.Id); - }); + constraints: table => { table.PrimaryKey("PK_People", x => x.Id); }); migrationBuilder.CreateTable( name: "Posts", diff --git a/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/BlogContextModelSnapshot.cs b/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/BlogContextModelSnapshot.cs index fe3a448b5a..442f1247dc 100644 --- a/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/BlogContextModelSnapshot.cs +++ b/samples/core/Schemas/TwoProjectMigrations/SqlServerMigrations/BlogContextModelSnapshot.cs @@ -1,14 +1,11 @@ -// -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using WorkerService1; namespace SqlServerMigrations { [DbContext(typeof(BlogContext))] - partial class BlogContextModelSnapshot : ModelSnapshot + internal class BlogContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -18,7 +15,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("ProductVersion", "5.0.0"); - modelBuilder.Entity("WorkerService1.Blog", b => + modelBuilder.Entity( + "WorkerService1.Blog", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -36,7 +34,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Blogs"); }); - modelBuilder.Entity("WorkerService1.Person", b => + modelBuilder.Entity( + "WorkerService1.Person", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -58,7 +57,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("People"); }); - modelBuilder.Entity("WorkerService1.Post", b => + modelBuilder.Entity( + "WorkerService1.Post", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -92,7 +92,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasDiscriminator("Discriminator").HasValue("Post"); }); - modelBuilder.Entity("WorkerService1.MediaPost", b => + modelBuilder.Entity( + "WorkerService1.MediaPost", b => { b.HasBaseType("WorkerService1.Post"); @@ -105,7 +106,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasDiscriminator().HasValue("MediaPost"); }); - modelBuilder.Entity("WorkerService1.Post", b => + modelBuilder.Entity( + "WorkerService1.Post", b => { b.HasOne("WorkerService1.Person", "Author") .WithMany("AuthoredPosts") @@ -124,15 +126,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Blog"); }); - modelBuilder.Entity("WorkerService1.Blog", b => - { - b.Navigation("Posts"); - }); + modelBuilder.Entity("WorkerService1.Blog", b => { b.Navigation("Posts"); }); - modelBuilder.Entity("WorkerService1.Person", b => - { - b.Navigation("AuthoredPosts"); - }); + modelBuilder.Entity("WorkerService1.Person", b => { b.Navigation("AuthoredPosts"); }); #pragma warning restore 612, 618 } } diff --git a/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/20200915230052_InitialCreate.cs b/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/20200915230052_InitialCreate.cs index e8f3808c46..878e70d3df 100644 --- a/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/20200915230052_InitialCreate.cs +++ b/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/20200915230052_InitialCreate.cs @@ -15,10 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Source = table.Column(type: "TEXT", nullable: true), Title = table.Column(type: "TEXT", nullable: true) }, - constraints: table => - { - table.PrimaryKey("PK_Blogs", x => x.Id); - }); + constraints: table => { table.PrimaryKey("PK_Blogs", x => x.Id); }); migrationBuilder.CreateTable( name: "People", @@ -29,10 +26,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Name = table.Column(type: "TEXT", nullable: true), Email = table.Column(type: "TEXT", nullable: true) }, - constraints: table => - { - table.PrimaryKey("PK_People", x => x.Id); - }); + constraints: table => { table.PrimaryKey("PK_People", x => x.Id); }); migrationBuilder.CreateTable( name: "Posts", diff --git a/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/BlogContextModelSnapshot.cs b/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/BlogContextModelSnapshot.cs index 2604baea48..006bfa98bd 100644 --- a/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/BlogContextModelSnapshot.cs +++ b/samples/core/Schemas/TwoProjectMigrations/SqliteMigrations/BlogContextModelSnapshot.cs @@ -1,13 +1,11 @@ -// -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using WorkerService1; namespace SqliteMigrations { [DbContext(typeof(BlogContext))] - partial class BlogContextModelSnapshot : ModelSnapshot + internal class BlogContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -15,7 +13,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder .HasAnnotation("ProductVersion", "5.0.0"); - modelBuilder.Entity("WorkerService1.Blog", b => + modelBuilder.Entity( + "WorkerService1.Blog", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -32,7 +31,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Blogs"); }); - modelBuilder.Entity("WorkerService1.Person", b => + modelBuilder.Entity( + "WorkerService1.Person", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -52,7 +52,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("People"); }); - modelBuilder.Entity("WorkerService1.Post", b => + modelBuilder.Entity( + "WorkerService1.Post", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -85,7 +86,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasDiscriminator("Discriminator").HasValue("Post"); }); - modelBuilder.Entity("WorkerService1.MediaPost", b => + modelBuilder.Entity( + "WorkerService1.MediaPost", b => { b.HasBaseType("WorkerService1.Post"); @@ -98,7 +100,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasDiscriminator().HasValue("MediaPost"); }); - modelBuilder.Entity("WorkerService1.Post", b => + modelBuilder.Entity( + "WorkerService1.Post", b => { b.HasOne("WorkerService1.Person", "Author") .WithMany("AuthoredPosts") @@ -117,15 +120,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Blog"); }); - modelBuilder.Entity("WorkerService1.Blog", b => - { - b.Navigation("Posts"); - }); + modelBuilder.Entity("WorkerService1.Blog", b => { b.Navigation("Posts"); }); - modelBuilder.Entity("WorkerService1.Person", b => - { - b.Navigation("AuthoredPosts"); - }); + modelBuilder.Entity("WorkerService1.Person", b => { b.Navigation("AuthoredPosts"); }); #pragma warning restore 612, 618 } } diff --git a/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Program.cs b/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Program.cs index b6886d014c..744cdcf1db 100644 --- a/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Program.cs +++ b/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Program.cs @@ -6,9 +6,9 @@ namespace WorkerService1 { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) => CreateHostBuilder(args).Build().Run(); #region snippet_CreateHostBuilder diff --git a/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Worker.cs b/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Worker.cs index e1a0c9cc05..aa37772738 100644 --- a/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Worker.cs +++ b/samples/core/Schemas/TwoProjectMigrations/WorkerService1/Worker.cs @@ -6,11 +6,11 @@ namespace WorkerService1 { - class Worker : IHostedService, IDisposable + internal class Worker : IHostedService, IDisposable { - readonly IServiceProvider _services; + private readonly IServiceProvider _services; - Timer _timer; + private Timer _timer; public Worker(IServiceProvider services) => _services = services; @@ -26,7 +26,7 @@ public Task StartAsync(CancellationToken stoppingToken) return Task.CompletedTask; } - void Execute() + private void Execute() { using var scope = _services.CreateScope(); var services = scope.ServiceProvider; diff --git a/samples/core/Schemas/TwoProjectMigrations/WorkerService1/WorkerService1.csproj b/samples/core/Schemas/TwoProjectMigrations/WorkerService1/WorkerService1.csproj index c7766b54b1..e9e4797e00 100644 --- a/samples/core/Schemas/TwoProjectMigrations/WorkerService1/WorkerService1.csproj +++ b/samples/core/Schemas/TwoProjectMigrations/WorkerService1/WorkerService1.csproj @@ -6,9 +6,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/core/Spatial/Projections/GeometryExtensions.cs b/samples/core/Spatial/Projections/GeometryExtensions.cs index e09517e0c3..5c55b34e8b 100644 --- a/samples/core/Spatial/Projections/GeometryExtensions.cs +++ b/samples/core/Spatial/Projections/GeometryExtensions.cs @@ -6,9 +6,9 @@ namespace NetTopologySuite.Geometries { #region snippet_GeometryExtensions - static class GeometryExtensions + internal static class GeometryExtensions { - static readonly CoordinateSystemServices _coordinateSystemServices + private static readonly CoordinateSystemServices _coordinateSystemServices = new CoordinateSystemServices( new Dictionary { @@ -19,7 +19,7 @@ static readonly CoordinateSystemServices _coordinateSystemServices // This coordinate system covers the area of our data. // Different data requires a different coordinate system. [2855] = - @" + @" PROJCS[""NAD83(HARN) / Washington North"", GEOGCS[""NAD83(HARN)"", DATUM[""NAD83_High_Accuracy_Regional_Network"", @@ -54,9 +54,9 @@ public static Geometry ProjectTo(this Geometry geometry, int srid) return result; } - class MathTransformFilter : ICoordinateSequenceFilter + private class MathTransformFilter : ICoordinateSequenceFilter { - readonly MathTransform _transform; + private readonly MathTransform _transform; public MathTransformFilter(MathTransform transform) => _transform = transform; @@ -78,4 +78,3 @@ public void Filter(CoordinateSequence seq, int i) } #endregion } - diff --git a/samples/core/Spatial/Projections/Program.cs b/samples/core/Spatial/Projections/Program.cs index dd52d8b1e4..497b6e043d 100644 --- a/samples/core/Spatial/Projections/Program.cs +++ b/samples/core/Spatial/Projections/Program.cs @@ -11,6 +11,5 @@ var distanceInDegrees = seattle.Distance(redmond); var distanceInMeters = seattle.ProjectTo(2855).Distance(redmond.ProjectTo(2855)); #endregion - Console.WriteLine($"Degrees: {distanceInDegrees:N4}"); Console.WriteLine($"Meters: {distanceInMeters:N0}"); diff --git a/samples/core/Spatial/SqlServer/Models/City.cs b/samples/core/Spatial/SqlServer/Models/City.cs index 0a87176611..873c86b1dc 100644 --- a/samples/core/Spatial/SqlServer/Models/City.cs +++ b/samples/core/Spatial/SqlServer/Models/City.cs @@ -5,7 +5,7 @@ namespace SqlServer.Models { #region snippet_City [Table("Cities", Schema = "Application")] - class City + internal class City { public int CityID { get; set; } diff --git a/samples/core/Spatial/SqlServer/Models/Country.cs b/samples/core/Spatial/SqlServer/Models/Country.cs index 899106a056..f99fe544b8 100644 --- a/samples/core/Spatial/SqlServer/Models/Country.cs +++ b/samples/core/Spatial/SqlServer/Models/Country.cs @@ -5,7 +5,7 @@ namespace SqlServer.Models { #region snippet_Country [Table("Countries", Schema = "Application")] - class Country + internal class Country { public int CountryID { get; set; } diff --git a/samples/core/Spatial/SqlServer/Models/StateProvince.cs b/samples/core/Spatial/SqlServer/Models/StateProvince.cs index 8e06a09643..a22d938cfc 100644 --- a/samples/core/Spatial/SqlServer/Models/StateProvince.cs +++ b/samples/core/Spatial/SqlServer/Models/StateProvince.cs @@ -4,7 +4,7 @@ namespace SqlServer.Models { [Table("StateProvinces", Schema = "Application")] - class StateProvince + internal class StateProvince { public int StateProvinceID { get; set; } diff --git a/samples/core/Spatial/SqlServer/Models/WideWorldImportersContext.cs b/samples/core/Spatial/SqlServer/Models/WideWorldImportersContext.cs index 74d8779327..52892f59ae 100644 --- a/samples/core/Spatial/SqlServer/Models/WideWorldImportersContext.cs +++ b/samples/core/Spatial/SqlServer/Models/WideWorldImportersContext.cs @@ -4,14 +4,14 @@ namespace SqlServer.Models { // This DbContext maps to the Wide World Importers sample database which can be // found at https://github.com/microsoft/sql-server-samples - class WideWorldImportersContext : DbContext + internal class WideWorldImportersContext : DbContext { public DbSet Cities { get; set; } public DbSet StateProvinces { get; set; } public DbSet Countries { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => - #region snippet_UseNetTopologySuite + #region snippet_UseNetTopologySuite options.UseSqlServer( @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=WideWorldImporters", x => x.UseNetTopologySuite()); diff --git a/samples/core/Spatial/SqlServer/Program.cs b/samples/core/Spatial/SqlServer/Program.cs index 85a49f777e..9f419d459f 100644 --- a/samples/core/Spatial/SqlServer/Program.cs +++ b/samples/core/Spatial/SqlServer/Program.cs @@ -5,10 +5,31 @@ using NetTopologySuite.IO; using SqlServer.Models; -var currentLocation = new Point(-122.128822, 47.643703) { SRID = 4326 }; +using (var context = new WideWorldImportersContext()) +{ + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); -using var db = new WideWorldImportersContext(); + context.AddRange( + new City { CityName = "Bellemondville", Location = new Point(-122.128822, 47.643703) { SRID = 4326 } }, + new Country + { + CountryName = "'Merica", + Border = new Polygon( + new LinearRing( + new[] + { + new Coordinate(-123.128822, 46.643703), new Coordinate(-121.128822, 46.643703), + new Coordinate(-121.128822, 48.643703), new Coordinate(-123.128822, 48.643703), + new Coordinate(-123.128822, 46.643703) + })) { SRID = 4326 } + }); + + context.SaveChanges(); +} +var currentLocation = new Point(-122.128822, 47.643703) { SRID = 4326 }; +using var db = new WideWorldImportersContext(); #region snippet_Distance // Find the nearest city var nearestCity = db.Cities @@ -16,7 +37,6 @@ .FirstOrDefault(); #endregion Console.WriteLine($"Nearest city: {nearestCity.CityName}"); - #region snippet_Contains // Find the containing country var currentCountry = db.Countries @@ -27,14 +47,11 @@ // Find which states/provinces a route intersects var route = new GeoJsonReader().Read(File.ReadAllText("seattle-to-new-york.json")); route.SRID = 4326; -var statePorvincesIntersected = Enumerable.ToList( - from s in db.StateProvinces - where s.Border.Intersects(route) - orderby s.Border.Distance(currentLocation) - select s); - +var statePorvincesIntersected = (from s in db.StateProvinces + where s.Border.Intersects(route) + orderby s.Border.Distance(currentLocation) + select s).ToList(); Console.WriteLine("States/provinces intersected:"); - foreach (var state in statePorvincesIntersected) { Console.WriteLine($"\t{state.StateProvinceName}"); diff --git a/samples/core/Spatial/SqlServer/SqlServer.csproj b/samples/core/Spatial/SqlServer/SqlServer.csproj index ee6d8136d4..a0474f9973 100644 --- a/samples/core/Spatial/SqlServer/SqlServer.csproj +++ b/samples/core/Spatial/SqlServer/SqlServer.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs b/samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs index 930d87daba..17c476f201 100644 --- a/samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs +++ b/samples/core/SqlServer/AzureDatabase/AzureSqlContext.cs @@ -8,7 +8,8 @@ public class AzureSqlContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer("Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[Login]@[serverName];Password=myPassword];Trusted_Connection=False;Encrypt=True;"); + optionsBuilder.UseSqlServer( + "Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[Login]@[serverName];Password=myPassword];Trusted_Connection=False;Encrypt=True;"); } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/samples/core/SqlServer/Program.cs b/samples/core/SqlServer/Program.cs index 2b1cb4c943..d8a1ca22ca 100644 --- a/samples/core/SqlServer/Program.cs +++ b/samples/core/SqlServer/Program.cs @@ -2,7 +2,7 @@ { public class Program { - static void Main() + private static void Main() { } } diff --git a/samples/core/SqlServer/SqlServer.csproj b/samples/core/SqlServer/SqlServer.csproj index 07f11a30eb..b1f0a506b8 100644 --- a/samples/core/SqlServer/SqlServer.csproj +++ b/samples/core/SqlServer/SqlServer.csproj @@ -6,7 +6,7 @@ - + diff --git a/samples/core/SqlServer/ValueGeneration/Blog.cs b/samples/core/SqlServer/ValueGeneration/Blog.cs index b71112829a..a72af3b3a8 100644 --- a/samples/core/SqlServer/ValueGeneration/Blog.cs +++ b/samples/core/SqlServer/ValueGeneration/Blog.cs @@ -1,6 +1,4 @@ -using System; - -namespace SqlServer.ValueGeneration +namespace SqlServer.ValueGeneration { public class Blog { diff --git a/samples/core/SqlServer/ValueGeneration/ExplicitIdentityValues.cs b/samples/core/SqlServer/ValueGeneration/ExplicitIdentityValues.cs index c7f384c972..80230621e5 100644 --- a/samples/core/SqlServer/ValueGeneration/ExplicitIdentityValues.cs +++ b/samples/core/SqlServer/ValueGeneration/ExplicitIdentityValues.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using Microsoft.EntityFrameworkCore; namespace SqlServer.ValueGeneration diff --git a/samples/core/SqlServer/ValueGeneration/IdentityOptionsContext.cs b/samples/core/SqlServer/ValueGeneration/IdentityOptionsContext.cs index e3b262f17e..3e1f6192e4 100644 --- a/samples/core/SqlServer/ValueGeneration/IdentityOptionsContext.cs +++ b/samples/core/SqlServer/ValueGeneration/IdentityOptionsContext.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using Microsoft.EntityFrameworkCore; namespace SqlServer.ValueGeneration