mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 04:35:29 +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")]
|
||||
|
@ -38,12 +38,12 @@ namespace SqlSugar.MongoDb
|
||||
}
|
||||
protected override string ToSingleSqlString(List<IGrouping<int, DbColumnInfo>> groupList)
|
||||
{
|
||||
var result = BuildUpdateMany(groupList, this.TableName);
|
||||
var result = BuildUpdateMany(groupList, this.TableName);
|
||||
return result;
|
||||
}
|
||||
protected override string TomultipleSqlString(List<IGrouping<int, DbColumnInfo>> groupList)
|
||||
{
|
||||
var result = BuildUpdateMany(groupList,this.TableName);
|
||||
var result = BuildUpdateMany(groupList, this.TableName);
|
||||
return result;
|
||||
}
|
||||
public string BuildUpdateMany(List<IGrouping<int, DbColumnInfo>> groupList, string tableName)
|
||||
@ -54,7 +54,7 @@ namespace SqlSugar.MongoDb
|
||||
{
|
||||
BsonArray filterArray = GetFilterArray();
|
||||
var filter = new BsonDocument("$and", filterArray);
|
||||
operations.Add($"{{ filter: {filter.ToJson(UtilMethods.GetJsonWriterSettings())} , update: {SetValues.FirstOrDefault().Value }}}");
|
||||
operations.Add($"{{ filter: {filter.ToJson(UtilMethods.GetJsonWriterSettings())} , update: {SetValues.FirstOrDefault().Value}}}");
|
||||
}
|
||||
else if (this.SetValues.Any())
|
||||
{
|
||||
@ -105,37 +105,26 @@ 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"))
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(ObjectId.Parse(col.Value?.ToString()));
|
||||
}
|
||||
else if (col.DataType == nameof(ObjectId))
|
||||
else
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(ObjectId.Parse(col.Value?.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
filter[col.DbColumnName] = UtilMethods.MyCreate(col.Value);
|
||||
}
|
||||
}
|
||||
else if (col.IsJson)
|
||||
{
|
||||
var bsonValue = UtilMethods.ParseJsonObject(col.Value?.ToString());
|
||||
setDoc[col.DbColumnName] = bsonValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (col.IsJson)
|
||||
{
|
||||
var bsonValue = UtilMethods.ParseJsonObject(col.Value?.ToString());
|
||||
setDoc[col.DbColumnName] = bsonValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var bsonValue = UtilMethods.MyCreate(col.Value);
|
||||
setDoc[col.DbColumnName] = bsonValue;
|
||||
}
|
||||
var bsonValue = UtilMethods.MyCreate(col.Value);
|
||||
setDoc[col.DbColumnName] = bsonValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user