mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-21 02:58:05 +08:00
ManyToMany query bug
This commit is contained in:
@@ -11,8 +11,8 @@ namespace OrmTest
|
|||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
var db = NewUnitTest.Db;
|
var db = NewUnitTest.Db;
|
||||||
db.CodeFirst.InitTables<OperatorInfo, Role, OptRole>();
|
db.CodeFirst.InitTables<OperatorInfo, Role, OptRole,RolePart>();
|
||||||
db.DbMaintenance.TruncateTable<OperatorInfo, Role, OptRole>();
|
db.DbMaintenance.TruncateTable<OperatorInfo, Role, OptRole,RolePart>();
|
||||||
db.Insertable(new OperatorInfo()
|
db.Insertable(new OperatorInfo()
|
||||||
{
|
{
|
||||||
id="1",
|
id="1",
|
||||||
@@ -69,6 +69,7 @@ namespace OrmTest
|
|||||||
name = "admin"
|
name = "admin"
|
||||||
|
|
||||||
}).ExecuteReturnIdentity();
|
}).ExecuteReturnIdentity();
|
||||||
|
db.Insertable(new RolePart() { Id = 1}).ExecuteCommand();
|
||||||
db.Insertable(new OptRole() { operId="1", roleId=id }).ExecuteCommand();
|
db.Insertable(new OptRole() { operId="1", roleId=id }).ExecuteCommand();
|
||||||
db.Insertable(new OptRole() { id=2, operId = "2", roleId = id2 }).ExecuteCommand();
|
db.Insertable(new OptRole() { id=2, operId = "2", roleId = id2 }).ExecuteCommand();
|
||||||
db.Queryable<OperatorInfo>()
|
db.Queryable<OperatorInfo>()
|
||||||
@@ -92,6 +93,10 @@ namespace OrmTest
|
|||||||
|
|
||||||
var list4 = db.Queryable<OperatorInfo>()
|
var list4 = db.Queryable<OperatorInfo>()
|
||||||
.Includes(x => x.Roles.Skip(10).Take(1).ToList())
|
.Includes(x => x.Roles.Skip(10).Take(1).ToList())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var list5 = db.Queryable<OperatorInfo>()
|
||||||
|
.Where(it => it.Roles.Any(z => z.RolePart.Id == 1))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
db.DeleteNav<OperatorInfo>(x=>x.id== list4.First().id)
|
db.DeleteNav<OperatorInfo>(x=>x.id== list4.First().id)
|
||||||
@@ -100,6 +105,9 @@ namespace OrmTest
|
|||||||
ManyToMayIsDeleteB=true
|
ManyToMayIsDeleteB=true
|
||||||
})
|
})
|
||||||
.ExecuteCommand();
|
.ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -196,7 +204,14 @@ namespace OrmTest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime createTime { get; set; }
|
public DateTime createTime { get; set; }
|
||||||
|
|
||||||
|
[Navigate(NavigateType.OneToOne,nameof(id))]
|
||||||
|
public RolePart RolePart { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RolePart
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey =true)]
|
||||||
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -152,6 +152,10 @@ namespace SqlSugar
|
|||||||
if (this.whereSql.HasValue())
|
if (this.whereSql.HasValue())
|
||||||
{
|
{
|
||||||
mapper.Sql = mapper.Sql.TrimEnd(')');
|
mapper.Sql = mapper.Sql.TrimEnd(')');
|
||||||
|
if (this.whereSql.Contains($" {PropertyShortName}."))
|
||||||
|
{
|
||||||
|
this.whereSql = this.whereSql.Replace($" {PropertyShortName}.", $" {this.ProPertyEntity.DbTableName}_1.");
|
||||||
|
}
|
||||||
mapper.Sql = mapper.Sql + " AND " + this.whereSql+")";
|
mapper.Sql = mapper.Sql + " AND " + this.whereSql+")";
|
||||||
}
|
}
|
||||||
if (MethodName == "Any")
|
if (MethodName == "Any")
|
||||||
|
Reference in New Issue
Block a user