mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-27 19:41:17 +08:00
Update mongodb
This commit is contained in:
parent
48c3e0e522
commit
c3e1d64cbd
@ -21,11 +21,16 @@ namespace MongoDbTest
|
||||
var student = new Student { Name = "TestStudent", SchoolId = ids.Last() };
|
||||
db.Insertable(student).ExecuteCommand();
|
||||
// 添加学生数据,SchoolId 关联学校并且没有学校
|
||||
var student2 = new Student { Name = "TestStudent", SchoolId =
|
||||
var student2 = new Student { Name = "TestStudentNoSchool", SchoolId =
|
||||
ObjectId.GenerateNewId().ToString()
|
||||
};
|
||||
db.Insertable(student2).ExecuteCommand();
|
||||
|
||||
|
||||
if (db.Queryable<Student>().First(it => it.SchoolId == ids.Last()).Name != "TestStudent") Cases.ThrowUnitError();
|
||||
db.Updateable(db.Queryable<Student>().First(it => it.SchoolId == ids.Last())).ExecuteCommand();
|
||||
if (db.Queryable<Student>().First(it => it.SchoolId == ids.Last()).Name != "TestStudent") Cases.ThrowUnitError();
|
||||
|
||||
//var list=db.Queryable<Student>()
|
||||
// .LeftJoin<School>((x, y) => x.SchoolId == y.Id)
|
||||
// .Where((x,y)=>x.Name =="a"||y.Name=="a")
|
||||
@ -38,7 +43,7 @@ namespace MongoDbTest
|
||||
public class Student : MongoDbBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(ColumnDataType =nameof(ObjectId))]
|
||||
public string SchoolId { get; set; }
|
||||
}
|
||||
[SqlSugar.SugarTable("UnitSchool123131")]
|
||||
|
@ -105,28 +105,18 @@ namespace SqlSugar.MongoDb
|
||||
foreach (var col in group)
|
||||
{
|
||||
|
||||
if (col.IsPrimarykey || pks.Contains(col.DbColumnName))
|
||||
if (col.DbColumnName.EqualCase("_id") || col.DataType == nameof(ObjectId))
|
||||
{
|
||||
if (col.Value == null)
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(col.Value);
|
||||
}
|
||||
else if(col.DbColumnName.EqualCase("_id"))
|
||||
else
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(ObjectId.Parse(col.Value?.ToString()));
|
||||
}
|
||||
else if (col.DataType == nameof(ObjectId))
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(ObjectId.Parse(col.Value?.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(col.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (col.IsJson)
|
||||
else if (col.IsJson)
|
||||
{
|
||||
var bsonValue = UtilMethods.ParseJsonObject(col.Value?.ToString());
|
||||
setDoc[col.DbColumnName] = bsonValue;
|
||||
@ -137,7 +127,6 @@ namespace SqlSugar.MongoDb
|
||||
setDoc[col.DbColumnName] = bsonValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var update = new BsonDocument
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user