mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-21 02:58:05 +08:00
Add demo
This commit is contained in:
@@ -30,6 +30,7 @@ namespace MongoDbTest
|
|||||||
//The primary key is not an ObjectId type use case
|
//The primary key is not an ObjectId type use case
|
||||||
LongPrimaryKey.Init();
|
LongPrimaryKey.Init();
|
||||||
GuidPrimaryKey.Init();
|
GuidPrimaryKey.Init();
|
||||||
|
StringPrimaryKey.Init();
|
||||||
}
|
}
|
||||||
public static void ThrowUnitError()
|
public static void ThrowUnitError()
|
||||||
{
|
{
|
||||||
|
@@ -44,7 +44,7 @@ namespace MongoDbTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SqlSugar.SugarTable("UnitStutsdsdfr5fazzz1")]
|
[SqlSugar.SugarTable("UnitStutsdsdfr5fazzz1")]
|
||||||
public class Student: MongoDbBaseLong
|
public class Student: MongoDbBaseLong//继承long主键
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
49
Src/Asp.NetCore2/MongoDbTest/UnitTest/StringPrimaryKey.cs
Normal file
49
Src/Asp.NetCore2/MongoDbTest/UnitTest/StringPrimaryKey.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using SqlSugar.MongoDb;
|
||||||
|
namespace MongoDbTest
|
||||||
|
{
|
||||||
|
internal class StringPrimaryKey
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = DbHelper.GetNewDb();
|
||||||
|
db.DbMaintenance.TruncateTable<Student>();
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
db.Insertable(new Student()
|
||||||
|
{
|
||||||
|
Name = "a",
|
||||||
|
Id = id
|
||||||
|
|
||||||
|
}).ExecuteCommand();
|
||||||
|
|
||||||
|
var data = db.Queryable<Student>().Where(it => it.Id == id).ToList();
|
||||||
|
if (data.First().Id != id) Cases.ThrowUnitError();
|
||||||
|
data.First().Name = "a2";
|
||||||
|
db.Updateable(data).ExecuteCommand();
|
||||||
|
var data2 = db.Queryable<Student>().Where(it => it.Id == id).ToList();
|
||||||
|
if (data.First().Name != "a2") Cases.ThrowUnitError();
|
||||||
|
Console.WriteLine(db.Queryable<Student>().Count());
|
||||||
|
db.Deleteable<Student>().Where(it => it.Id == id).ExecuteCommand();
|
||||||
|
if (db.Queryable<Student>().Count() != 0) Cases.ThrowUnitError();
|
||||||
|
db.Insertable(new Student()
|
||||||
|
{
|
||||||
|
Name = "a",
|
||||||
|
Id = id
|
||||||
|
}).ExecuteCommand();
|
||||||
|
var rows = db.Deleteable<Student>().Where(it => new string[] { id }.Contains(it.Id)).ExecuteCommand();
|
||||||
|
if (db.Queryable<Student>().Count() != 0) Cases.ThrowUnitError();
|
||||||
|
db.Insertable(new Student()
|
||||||
|
{
|
||||||
|
Name = "a",
|
||||||
|
Id = id
|
||||||
|
}).ExecuteCommand();
|
||||||
|
var row2 = db.Deleteable<Student>(new Student() { Id = id }).ExecuteCommand();
|
||||||
|
if (db.Queryable<Student>().Count() != 0) Cases.ThrowUnitError();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SqlSugar.SugarTable("UnitStutsdsdfr5fazzz1")]
|
||||||
|
public class Student : MongoDbBaseString //继承string主键
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user