Skip to content
This repository was archived by the owner on Jul 24, 2022. It is now read-only.

Commit 4ccb2f4

Browse files
committed
调整使得 Add 可以保存成功。
1 parent baeedc2 commit 4ccb2f4

File tree

61 files changed

+1160
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1160
-389
lines changed

.dockerignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,4 @@ ASALocalRun/
340340

341341
# Local History for Visual Studio
342342
.localhistory/
343+
/data

EFCore.MongoDB.sln

+21
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ MinimumVisualStudioVersion = 17.0.31521.260
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B9E4CC99-199C-4E3B-9EC5-D1FDFCD6C27B}"
77
ProjectSection(SolutionItems) = preProject
88
.editorconfig = .editorconfig
9+
README.md = README.md
910
EndProjectSection
1011
EndProject
1112
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}"
1213
EndProject
1314
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.MongoDB", "src\EFCore.MongoDB\EFCore.MongoDB.csproj", "{D0D567AA-0B92-4D9C-B9E2-459D3FDDB94C}"
1415
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "src\Sample\Sample.csproj", "{8ECD3920-1B7D-48E4-88FC-0CE56B5C7A9A}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Console", "src\Sample.Console\Sample.Console.csproj", "{A1BC8135-0580-49AE-BC9D-DB16E816DB7A}"
19+
EndProject
20+
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{5EB83A3C-4101-46B7-AD63-83AD3576AC4C}"
21+
EndProject
1522
Global
1623
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1724
Debug|Any CPU = Debug|Any CPU
@@ -22,12 +29,26 @@ Global
2229
{D0D567AA-0B92-4D9C-B9E2-459D3FDDB94C}.Debug|Any CPU.Build.0 = Debug|Any CPU
2330
{D0D567AA-0B92-4D9C-B9E2-459D3FDDB94C}.Release|Any CPU.ActiveCfg = Release|Any CPU
2431
{D0D567AA-0B92-4D9C-B9E2-459D3FDDB94C}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{8ECD3920-1B7D-48E4-88FC-0CE56B5C7A9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{8ECD3920-1B7D-48E4-88FC-0CE56B5C7A9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{8ECD3920-1B7D-48E4-88FC-0CE56B5C7A9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{8ECD3920-1B7D-48E4-88FC-0CE56B5C7A9A}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{A1BC8135-0580-49AE-BC9D-DB16E816DB7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{A1BC8135-0580-49AE-BC9D-DB16E816DB7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{A1BC8135-0580-49AE-BC9D-DB16E816DB7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{A1BC8135-0580-49AE-BC9D-DB16E816DB7A}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{5EB83A3C-4101-46B7-AD63-83AD3576AC4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{5EB83A3C-4101-46B7-AD63-83AD3576AC4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{5EB83A3C-4101-46B7-AD63-83AD3576AC4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{5EB83A3C-4101-46B7-AD63-83AD3576AC4C}.Release|Any CPU.Build.0 = Release|Any CPU
2544
EndGlobalSection
2645
GlobalSection(SolutionProperties) = preSolution
2746
HideSolutionNode = FALSE
2847
EndGlobalSection
2948
GlobalSection(NestedProjects) = preSolution
3049
{D0D567AA-0B92-4D9C-B9E2-459D3FDDB94C} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
50+
{8ECD3920-1B7D-48E4-88FC-0CE56B5C7A9A} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
51+
{A1BC8135-0580-49AE-BC9D-DB16E816DB7A} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
3152
EndGlobalSection
3253
GlobalSection(ExtensibilityGlobals) = postSolution
3354
SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705}

docker-compose.dcproj

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
3+
<PropertyGroup Label="Globals">
4+
<ProjectVersion>2.1</ProjectVersion>
5+
<DockerTargetOS>Linux</DockerTargetOS>
6+
<ProjectGuid>5eb83a3c-4101-46b7-ad63-83ad3576ac4c</ProjectGuid>
7+
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
8+
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}</DockerServiceUrl>
9+
<DockerServiceName>sample</DockerServiceName>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<None Include="docker-compose.override.yml">
13+
<DependentUpon>docker-compose.yml</DependentUpon>
14+
</None>
15+
<None Include="docker-compose.yml" />
16+
<None Include=".dockerignore" />
17+
</ItemGroup>
18+
</Project>

docker-compose.override.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.4'
2+
3+
services:
4+
sample:
5+
environment:
6+
- ASPNETCORE_ENVIRONMENT=Development
7+
- ASPNETCORE_URLS=https://+:443;http://+:80
8+
ports:
9+
- "80"
10+
- "443"
11+
volumes:
12+
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
13+
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

docker-compose.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: '3.4'
2+
3+
services:
4+
mongodb:
5+
image: mongo:latest
6+
restart: always
7+
container_name: mongodb
8+
volumes:
9+
- ./data/mongodb/db:/data/db
10+
- ./data/mongodb/log:/var/log/mongodb
11+
ports:
12+
- 27017:27017
13+
environment:
14+
TZ: "Asia/Shanghai"
15+
MONGO_INITDB_ROOT_USERNAME: root
16+
MONGO_INITDB_ROOT_PASSWORD: kissme
17+
networks:
18+
- mongo-network
19+
20+
21+
sample.console:
22+
image: ${DOCKER_REGISTRY-}sampleconsole
23+
build:
24+
context: .
25+
dockerfile: src/Sample.Console/Dockerfile
26+
depends_on:
27+
- mongodb
28+
links:
29+
- mongodb
30+
networks:
31+
- mongo-network
32+
33+
34+
sample:
35+
image: ${DOCKER_REGISTRY-}sample
36+
build:
37+
context: .
38+
dockerfile: src/Sample/Dockerfile
39+
depends_on:
40+
- mongodb
41+
links:
42+
- mongodb
43+
networks:
44+
- mongo-network
45+
46+
networks:
47+
mongo-network:
48+
driver: bridge
49+

launchSettings.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"profiles": {
3+
"Docker Compose": {
4+
"commandName": "DockerCompose",
5+
"composeLaunchAction": "None",
6+
"composeLaunchServiceName": "sample.console",
7+
"commandVersion": "1.0",
8+
"serviceActions": {
9+
"mongodb": "StartWithoutDebugging",
10+
"sample": "DoNotStart",
11+
"sample.console": "StartDebugging"
12+
}
13+
}
14+
}
15+
}

src/EFCore.MongoDB/Diagnostics/Internal/MongoDBLoggerExtensions.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
using System.Text;
66
using IoTSharp.EntityFrameworkCore.MongoDB.Internal;
77
using IoTSharp.EntityFrameworkCore.MongoDB.Storage.Internal;
8-
using Newtonsoft.Json;
9-
using Newtonsoft.Json.Linq;
8+
109

1110
// ReSharper disable once CheckNamespace
1211
namespace IoTSharp.EntityFrameworkCore.MongoDB.Diagnostics.Internal;
@@ -467,8 +466,8 @@ private static void FormatParameterValue(StringBuilder builder, object? paramete
467466

468467
switch (parameterValue)
469468
{
470-
case JToken jTokenValue:
471-
builder.Append(jTokenValue.ToString(Formatting.None).Trim('"'));
469+
case BsonValue jTokenValue:
470+
builder.Append(jTokenValue.ToString()?.Trim('"'));
472471
break;
473472
case DateTime dateTimeValue:
474473
builder.Append(dateTimeValue.ToString("s"));

src/EFCore.MongoDB/EFCore.MongoDB.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
<Using Include="Microsoft.EntityFrameworkCore.Utilities" />
3333
<Using Include="Microsoft.Extensions.Logging" />
3434
<Using Include="Microsoft.Extensions.DependencyInjection" />
35-
<Using Include="MongoDB.Driver"/>
35+
<Using Include="MongoDB.Driver" />
36+
<Using Include="MongoDB.Bson"/>
3637
</ItemGroup>
3738

3839
<ItemGroup>
@@ -49,8 +50,6 @@
4950
</PackageReference>
5051
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.2" />
5152
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
52-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
53-
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
5453
</ItemGroup>
5554

5655
<ItemGroup>

src/EFCore.MongoDB/Extensions/MongoDBDbContextOptionsExtensions.cs

+5-38
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,7 @@ namespace IoTSharp.EntityFrameworkCore.MongoDB.Extensions;
1616
/// </remarks>
1717
public static class MongoDBDbContextOptionsExtensions
1818
{
19-
/// <summary>
20-
/// Configures the context to connect to an Azure MongoDB database.
21-
/// </summary>
22-
/// <remarks>
23-
/// See <see href="https://aka.ms/efcore-docs-dbcontext-options">Using DbContextOptions</see>, and
24-
/// <see href="https://aka.ms/efcore-docs-MongoDB">Accessing Azure MongoDB DB with EF Core</see> for more information and examples.
25-
/// </remarks>
26-
/// <typeparam name="TContext">The type of context to be configured.</typeparam>
27-
/// <param name="optionsBuilder">The builder being used to configure the context.</param>
28-
/// <param name="accountEndpoint">The account end-point to connect to.</param>
29-
/// <param name="accountKey">The account key.</param>
30-
/// <param name="databaseName">The database name.</param>
31-
/// <param name="MongoDBOptionsAction">An optional action to allow additional MongoDB-specific configuration.</param>
32-
/// <returns>The options builder so that further configuration can be chained.</returns>
33-
public static DbContextOptionsBuilder<TContext> UseMongoDB<TContext>(
34-
this DbContextOptionsBuilder<TContext> optionsBuilder,
35-
string accountEndpoint,
36-
string accountKey,
37-
string databaseName,
38-
Action<MongoDBDbContextOptionsBuilder>? MongoDBOptionsAction = null)
39-
where TContext : DbContext
40-
=> (DbContextOptionsBuilder<TContext>)((DbContextOptionsBuilder)optionsBuilder).UseMongoDB(
41-
accountEndpoint,
42-
accountKey,
43-
databaseName,
44-
MongoDBOptionsAction);
19+
4520

4621
/// <summary>
4722
/// Configures the context to connect to an Azure MongoDB database.
@@ -51,30 +26,22 @@ public static DbContextOptionsBuilder<TContext> UseMongoDB<TContext>(
5126
/// <see href="https://aka.ms/efcore-docs-MongoDB">Accessing Azure MongoDB DB with EF Core</see> for more information and examples.
5227
/// </remarks>
5328
/// <param name="optionsBuilder">The builder being used to configure the context.</param>
54-
/// <param name="accountEndpoint">The account end-point to connect to.</param>
55-
/// <param name="accountKey">The account key.</param>
56-
/// <param name="databaseName">The database name.</param>
29+
/// <param name="connectionString"></param>
5730
/// <param name="MongoDBOptionsAction">An optional action to allow additional MongoDB-specific configuration.</param>
5831
/// <returns>The options builder so that further configuration can be chained.</returns>
5932
public static DbContextOptionsBuilder UseMongoDB(
6033
this DbContextOptionsBuilder optionsBuilder,
61-
string accountEndpoint,
62-
string accountKey,
63-
string databaseName,
34+
string connectionString,
6435
Action<MongoDBDbContextOptionsBuilder>? MongoDBOptionsAction = null)
6536
{
6637
Check.NotNull(optionsBuilder, nameof(optionsBuilder));
67-
Check.NotNull(accountEndpoint, nameof(accountEndpoint));
68-
Check.NotEmpty(accountKey, nameof(accountKey));
69-
Check.NotEmpty(databaseName, nameof(databaseName));
38+
Check.NotEmpty(connectionString, nameof(connectionString));
7039

7140
var extension = optionsBuilder.Options.FindExtension<MongoDBOptionsExtension>()
7241
?? new MongoDBOptionsExtension();
7342

7443
extension = extension
75-
.WithAccountEndpoint(accountEndpoint)
76-
.WithAccountKey(accountKey)
77-
.WithDatabaseName(databaseName);
44+
.WithConnectionString(connectionString);
7845

7946
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);
8047

src/EFCore.MongoDB/Extensions/MongoDBEntityTypeExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public static class MongoDBEntityTypeExtensions
3030
private static string? GetDefaultContainer(IReadOnlyEntityType entityType)
3131
=> entityType.FindOwnership() != null
3232
? null
33-
: entityType.Model.GetDefaultContainer()
34-
?? entityType.ShortName();
33+
: entityType.ShortName()
34+
?? entityType.Model.GetDefaultContainer();
3535

3636
/// <summary>
3737
/// Sets the name of the container to which the entity type is mapped.

src/EFCore.MongoDB/Metadata/Conventions/Internal/MongoDBConventionSetBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static IServiceScope CreateServiceScope()
154154
.AddEntityFrameworkMongoDB()
155155
.AddDbContext<DbContext>(
156156
(p, o) =>
157-
o.UseMongoDB("localhost", "_", "_")
157+
o.UseMongoDB("localhost", "_")
158158
.UseInternalServiceProvider(p))
159159
.BuildServiceProvider();
160160

src/EFCore.MongoDB/Metadata/Conventions/StoreKeyConvention.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using IoTSharp.EntityFrameworkCore.MongoDB.Extensions;
55
using IoTSharp.EntityFrameworkCore.MongoDB.Metadata.Internal;
66
using IoTSharp.EntityFrameworkCore.MongoDB.ValueGeneration;
7-
using Newtonsoft.Json.Linq;
87

98
// ReSharper disable once CheckNamespace
109
namespace IoTSharp.EntityFrameworkCore.MongoDB.Metadata.Conventions;
@@ -150,7 +149,7 @@ private static void ProcessJObjectProperty(IConventionEntityTypeBuilder entityTy
150149
if (entityType.BaseType == null
151150
&& !entityType.IsKeyless)
152151
{
153-
var jObjectProperty = entityTypeBuilder.Property(typeof(JObject), JObjectPropertyName);
152+
var jObjectProperty = entityTypeBuilder.Property(typeof(BsonDocument), JObjectPropertyName);
154153
jObjectProperty?.ToJsonProperty("");
155154
jObjectProperty?.ValueGenerated(ValueGenerated.OnAddOrUpdate);
156155
}

0 commit comments

Comments
 (0)