mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-09 02:44:58 +08:00
Update mongodb json
This commit is contained in:
@@ -139,6 +139,7 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
var doc = item.AsBsonDocument;
|
||||
var obj = BsonSerializer.Deserialize(doc, elementType);
|
||||
UtilMethods.ConvertDateTimeToUnspecified(obj);
|
||||
resultList.Add(obj);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -21,6 +21,26 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
public static void ConvertDateTimeToUnspecified(object o)
|
||||
{
|
||||
if (o == null) return;
|
||||
|
||||
var type = o.GetType();
|
||||
foreach (var prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
if (!prop.CanRead || !prop.CanWrite) continue;
|
||||
|
||||
var value = prop.GetValue(o);
|
||||
if (value is DateTime dt)
|
||||
{
|
||||
prop.SetValue(o, DateTime.SpecifyKind(dt, DateTimeKind.Unspecified));
|
||||
}
|
||||
else if (value != null && !prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum && prop.PropertyType != typeof(string))
|
||||
{
|
||||
ConvertDateTimeToUnspecified(value); // Recursive for nested objects
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static bool IsJsonMember(Expression expression, SqlSugarProvider context)
|
||||
{
|
||||
var member = expression as MemberExpression;
|
||||
|
||||
Reference in New Issue
Block a user