Add unit test

This commit is contained in:
sunkaixuan
2022-04-13 22:01:14 +08:00
parent 666423f86e
commit c5ee5bf182
2 changed files with 14 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ namespace OrmTest
DbType = DbType.SqlServer, DbType = DbType.SqlServer,
IsAutoCloseConnection = true IsAutoCloseConnection = true
}); });
db.CodeFirst.InitTables<Country111, Province111, City111>(); db.CodeFirst.InitTables<Country111, Province111, City111>();
db.DbMaintenance.TruncateTable("Country111"); db.DbMaintenance.TruncateTable("Country111");
db.DbMaintenance.TruncateTable("Province111"); db.DbMaintenance.TruncateTable("Province111");
@@ -84,7 +84,10 @@ namespace OrmTest
} }
} }
}).ExecuteCommand(); }).ExecuteCommand();
db.Aop.OnLogExecuted = (sq, p) =>
{
Console.WriteLine(sq);
};
var list=db.Queryable<Country111>() var list=db.Queryable<Country111>()
.Includes(x => x.Provinces.OrderByDescending(x111=>x111.Id).ToList()) .Includes(x => x.Provinces.OrderByDescending(x111=>x111.Id).ToList())
.ToList(); .ToList();
@@ -99,30 +102,33 @@ namespace OrmTest
.ToList(); .ToList();
} }
[SugarTable("Country_111")]
public class Country111 public class Country111
{ {
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "cid")]
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
[Navigat(NavigatType.OneToMany,nameof(Province111.CountryId))] [Navigat(NavigatType.OneToMany,nameof(Province111.CountryId))]
public List<Province111> Provinces { get; set; } public List<Province111> Provinces { get; set; }
} }
[SugarTable("Province_111")]
public class Province111 public class Province111
{ {
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "pid")]
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
[SugarColumn(ColumnName = "coid")]
public int CountryId { get; set; } public int CountryId { get; set; }
[Navigat(NavigatType.OneToMany, nameof(City111.ProvinceId))] [Navigat(NavigatType.OneToMany, nameof(City111.ProvinceId))]
public List<City111> citys { get; set; } public List<City111> citys { get; set; }
} }
[SugarTable("City_111")]
public class City111 public class City111
{ {
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "cid")]
public int Id { get; set; } public int Id { get; set; }
[SugarColumn(ColumnName="ppid")]
public int ProvinceId { get; set; } public int ProvinceId { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }

View File

@@ -238,7 +238,7 @@ namespace SqlSugar
conditionalModels.Add((new ConditionalModel() conditionalModels.Add((new ConditionalModel()
{ {
ConditionalType = ConditionalType.In, ConditionalType = ConditionalType.In,
FieldName = navObjectNameColumnInfo.Navigat.Name, FieldName = navColumn.DbColumnName,
FieldValue = String.Join(",", ids), FieldValue = String.Join(",", ids),
CSharpTypeName = listItemPkColumn.PropertyInfo.PropertyType.Name CSharpTypeName = listItemPkColumn.PropertyInfo.PropertyType.Name
})); }));