Browse Source

Add unit test

pull/18/head
sunkaixuan 3 years ago
parent
commit
9c81533abf
  1. 9
      Src/Asp.Net/SqlServerTest/UnitTest/UCustom012.cs
  2. 28
      Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToMany.cs

9
Src/Asp.Net/SqlServerTest/UnitTest/UCustom012.cs

@ -51,7 +51,7 @@ namespace OrmTest
db.Insertable(new BookA() { BookId = 3, Names = "c#1", studenId = 2 }).ExecuteCommand();
db.Insertable(new BookA() { BookId = 4, Names = "php", studenId = 3 }).ExecuteCommand();
db.Insertable(new BookA() { BookId = 5, Names = "js", studenId = 4 }).ExecuteCommand();
db.Insertable(new BookA() { BookId = 6, Names = "北大jack", studenId = 1 }).ExecuteCommand();
var list2 = db.Queryable<StudentA>()
.Includes(x => x.SchoolA, x => x.RoomList)//2个参数就是 then Include
@ -73,6 +73,13 @@ namespace OrmTest
.Where(x => x.Books.Any(z => z.BookId == 1))
.Where(x => x.SchoolA.School_Name == "北大")
.ToList();
var list3_1 = db.Queryable<StudentA>()
.Includes(x => x.Books.MappingField(z=>z.Names,()=>x.Name).ToList())
.ToList();
//先用Mapper导航映射查出第二层
var list = db.Queryable<StudentA>().Mapper(x => x.SchoolA, x => x.SchoolId).ToList();

28
Src/Asp.Net/SqlServerTest/UnitTest/UnitManyToMany.cs

@ -27,23 +27,45 @@ namespace OrmTest
sno="a",
username="a01"
}).ExecuteCommand();
db.Insertable(new OperatorInfo()
{
id = "2",
createTime = DateTime.Now,
isDel = 1,
isDisabled = 1,
openid = "",
phone = "",
pwd = "",
realname = "a01",
remark = "a",
sno = "a",
username = "admin"
}).ExecuteCommand();
var id=db.Insertable(new Role()
{
id=1,
createTime=DateTime.Now,
name="admin"
}).ExecuteReturnIdentity();
var id2 = db.Insertable(new Role()
{
id = 2,
createTime = DateTime.Now,
name = "admin"
}).ExecuteReturnIdentity();
db.Insertable(new OptRole() { operId="1", roleId=id }).ExecuteCommand();
db.Insertable(new OptRole() { id=2, operId = "2", roleId = id2 }).ExecuteCommand();
db.Queryable<OperatorInfo>()
.Includes(x => x.Roles).Where(x => x.Roles.Any(z=>z.id==1))
.ToList();
var list=db.Queryable<OperatorInfo>()
.Includes(x => x.Roles).Where(x => x.Roles.Any())
.ToListAsync().GetAwaiter().GetResult();
//db.Queryable<OperatorInfo>()
// .Includes(x => x.Roles.Where(z=>z.name==x.realname).ToList())
// .ToList();
var list2=db.Queryable<OperatorInfo>()
.Includes(x => x.Roles.MappingField(z=>z.name,()=>x.username).ToList())
.ToList();
}
/// <summary>

Loading…
Cancel
Save