mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 18:48:09 +08:00
Update mongodb
This commit is contained in:
76
Src/Asp.NetCore2/MongoDbTest/UnitTest/Unitdfasfysfs.cs
Normal file
76
Src/Asp.NetCore2/MongoDbTest/UnitTest/Unitdfasfysfs.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using MongoDB.Bson;
|
||||
using SqlSugar.MongoDb;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbTest
|
||||
{
|
||||
internal class Unitdfasfysfs
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = DbHelper.GetNewDb();
|
||||
db.Insertable(new VehicleTracksEO()
|
||||
{
|
||||
carId= ObjectId.GenerateNewId() + "",
|
||||
orderId =ObjectId.GenerateNewId()+"",
|
||||
latlngPoints=new List<Point>() {
|
||||
new Point(){ lat=1, lng=1, timestamp=11, vehicleNo="aa" }
|
||||
}
|
||||
|
||||
}).ExecuteCommand();
|
||||
var list=db.Queryable<VehicleTracksEO>().ToList();
|
||||
}
|
||||
}
|
||||
[SugarTable("unitadsfasfdsys")]
|
||||
|
||||
public class VehicleTracksEO : MongoDbBase
|
||||
|
||||
{
|
||||
|
||||
//外键需要设置ObjectId类型不然存储会的是string
|
||||
|
||||
[SugarColumn(ColumnDataType = nameof(ObjectId))]
|
||||
|
||||
public string orderId { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
[SugarColumn(ColumnDataType = nameof(ObjectId))]
|
||||
|
||||
public string carId { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
[SugarColumn(IsJson = true)]
|
||||
|
||||
public List<Point> latlngPoints { get; set; } =new List<Point>() { };
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class Point
|
||||
|
||||
{
|
||||
|
||||
public string? vehicleNo { get; set; } = string.Empty;
|
||||
|
||||
|
||||
|
||||
public double lat { get; set; }
|
||||
|
||||
|
||||
|
||||
public double lng { get; set; }
|
||||
|
||||
|
||||
|
||||
public long timestamp { get; set; }
|
||||
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using Dm.util;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.IO;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -88,7 +89,8 @@ namespace SqlSugar.MongoDb
|
||||
}
|
||||
else
|
||||
{
|
||||
var arrayObj = BsonArray.Create(json);
|
||||
using var reader = new JsonReader(json?.toString());
|
||||
var arrayObj = BsonSerializer.Deserialize<BsonValue>(reader);
|
||||
return arrayObj;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user