mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
![]() |
using SqlSugar.MongoDb;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Collections.Immutable;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace MongoDbTest
|
|||
|
{
|
|||
|
internal class LongPrimaryKey
|
|||
|
{
|
|||
|
public static void Init()
|
|||
|
{
|
|||
|
var db = DbHelper.GetNewDb();
|
|||
|
db.DbMaintenance.TruncateTable<Student>();
|
|||
|
var id=db.Insertable(new Student()
|
|||
|
{
|
|||
|
Name="a"
|
|||
|
|
|||
|
}).ExecuteReturnSnowflakeId();
|
|||
|
|
|||
|
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();
|
|||
|
id = db.Insertable(new Student()
|
|||
|
{
|
|||
|
Name = "a"
|
|||
|
}).ExecuteReturnSnowflakeId();
|
|||
|
var rows=db.Deleteable<Student>().Where(it => new long[] { id}.Contains(it.Id)).ExecuteCommand();
|
|||
|
if (db.Queryable<Student>().Count() != 0) Cases.ThrowUnitError();
|
|||
|
id = db.Insertable(new Student()
|
|||
|
{
|
|||
|
Name = "a"
|
|||
|
}).ExecuteReturnSnowflakeId();
|
|||
|
var row2=db.Deleteable<Student>(new Student() { Id=id}).ExecuteCommand();
|
|||
|
if (db.Queryable<Student>().Count() != 0) Cases.ThrowUnitError();
|
|||
|
}
|
|||
|
|
|||
|
[SqlSugar.SugarTable("UnitStutsdsdfr5fazzz1")]
|
|||
|
public class Student
|
|||
|
{
|
|||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true,ColumnName ="_id")]
|
|||
|
public long Id { get; set; }
|
|||
|
public string Name { get; set; }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|