Update mongodb

This commit is contained in:
sunkaixuan
2025-10-04 11:25:44 +08:00
parent 61a35f2a56
commit a92d5ef77a

View File

@@ -147,6 +147,12 @@ namespace SqlSugar.MongoDb
return arrayObj;
}
}
internal static object DateOnlyToDateTime(object value)
{
if (value == null) return null;
var method = value.GetType().GetMethods().First(it => it.GetParameters().Length == 0 && it.Name == "ToShortDateString");
return method.Invoke(value, new object[] { });
}
public static BsonValue MyCreate(object value)
{
if (value is DateTime dt)
@@ -162,6 +168,10 @@ namespace SqlSugar.MongoDb
{
value = ObjectId.Parse(s);
}
else if (value!=null&&value?.GetType()?.Name=="DateOnly")
{
value = Convert.ToDateTime(DateOnlyToDateTime(value)).ToString("yyyy-MM-dd");
}
return BsonValue.Create(value);
}
internal static MongoDB.Bson.IO.JsonWriterSettings GetJsonWriterSettings()