From 94acdc6c3a33c79b68c11548905b196a42c257c5 Mon Sep 17 00:00:00 2001
From: 2881099 <2881099@qq.com>
Date: Thu, 14 Dec 2023 14:26:19 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20=E4=BD=8E=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=20ZoreEntity=20=E8=BF=81=E7=A7=BB=20API=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Examples/zore_entity/JObjectExtensions.cs | 68 ++++
Examples/zore_entity/Program.cs | 297 ++++++++++++++++++
Examples/zore_entity/zore_entity.csproj | 19 ++
.../FreeSql.Extensions.ZoreEntity.csproj | 2 +-
.../ZoreDbContext.cs | 7 +
FreeSql-ZoreEntity.sln | 40 +++
FreeSql.DbContext/FreeSql.DbContext.xml | 18 --
FreeSql/FreeSql.xml | 288 -----------------
8 files changed, 432 insertions(+), 307 deletions(-)
create mode 100644 Examples/zore_entity/JObjectExtensions.cs
create mode 100644 Examples/zore_entity/Program.cs
create mode 100644 Examples/zore_entity/zore_entity.csproj
create mode 100644 FreeSql-ZoreEntity.sln
diff --git a/Examples/zore_entity/JObjectExtensions.cs b/Examples/zore_entity/JObjectExtensions.cs
new file mode 100644
index 00000000..d8ef3fc9
--- /dev/null
+++ b/Examples/zore_entity/JObjectExtensions.cs
@@ -0,0 +1,68 @@
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+public static class JObjectExtensions
+{
+ ///
+ /// 将JObject转化成字典
+ ///
+ ///
+ ///
+ public static Dictionary ToDictionary(this JToken json)
+ {
+ var propertyValuePairs = json.ToObject>();
+ ProcessJObjectProperties(propertyValuePairs);
+ ProcessJArrayProperties(propertyValuePairs);
+ return propertyValuePairs;
+ }
+
+ private static void ProcessJObjectProperties(Dictionary propertyValuePairs)
+ {
+ var objectPropertyNames = (from property in propertyValuePairs
+ let propertyName = property.Key
+ let value = property.Value
+ where value is JObject
+ select propertyName).ToList();
+
+ objectPropertyNames.ForEach(propertyName => propertyValuePairs[propertyName] = ToDictionary((JObject)propertyValuePairs[propertyName]));
+ }
+
+ private static void ProcessJArrayProperties(Dictionary propertyValuePairs)
+ {
+ var arrayPropertyNames = (from property in propertyValuePairs
+ let propertyName = property.Key
+ let value = property.Value
+ where value is JArray
+ select propertyName).ToList();
+
+ arrayPropertyNames.ForEach(propertyName => propertyValuePairs[propertyName] = ToArray((JArray)propertyValuePairs[propertyName]));
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static object[] ToArray(this JArray array)
+ {
+ return array.ToObject