mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 AsType 表达式解析问题;#1389
This commit is contained in:
parent
1613307f26
commit
36f3db5525
@ -491,6 +491,17 @@ namespace base_entity
|
||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||
#endregion
|
||||
|
||||
var sqlv01 = fsql.Select<BaseDataEntity>().AsType(typeof(GoodsData))
|
||||
.ToSql(v => new GoodsDataDTO()
|
||||
{
|
||||
Id = v.Id,
|
||||
GoodsNo = v.Code,
|
||||
GoodsName = v.Name,
|
||||
});
|
||||
// 解析会连带导出 CategoryId ,但是如果查询别名不是 a 时就会重置到基类表
|
||||
// SELECT a.`CategoryId` as1, v.`Id` as2, v.`Code` as3, v.`Name` as4
|
||||
// FROM `FreeSqlTest`.`bdd_1` a, `BaseDataEntity` v
|
||||
|
||||
var groupsql01 = fsql.Select<User1>()
|
||||
.GroupBy(a => new
|
||||
{
|
||||
@ -524,9 +535,9 @@ namespace base_entity
|
||||
fsql.Insert(listaaaddd).ExecuteAffrows(); //加在事务里就出错
|
||||
});
|
||||
|
||||
fsql.Select<IdentityTable>().Count();
|
||||
fsql.Select<IdentityTable>().Count();
|
||||
|
||||
var dkdksql = fsql.Select<User1>().WithLock().From<UserGroup>()
|
||||
var dkdksql = fsql.Select<User1>().WithLock().From<UserGroup>()
|
||||
.InnerJoin<UserGroup>((user, usergroup) => user.GroupId == usergroup.Id && usergroup.GroupName == "xxx")
|
||||
.ToSql();
|
||||
|
||||
@ -791,7 +802,7 @@ namespace base_entity
|
||||
.Where(a => a.Id == a1id1 || a.Id == a1id2)
|
||||
.ToSql();
|
||||
var sql1a2 = fsql.Select<User1, UserGroup>()
|
||||
.InnerJoin((a,b)=> a.GroupId == b.Id)
|
||||
.InnerJoin((a, b) => a.GroupId == b.Id)
|
||||
.Where((a, b) => a.Id == a1id1)
|
||||
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型
|
||||
|
||||
@ -823,8 +834,8 @@ namespace base_entity
|
||||
|
||||
fsql.CodeFirst.ConfigEntity<TestClass>(cf =>
|
||||
{
|
||||
cf.Property(p => p.Name).IsNullable(false);
|
||||
cf.Property(p => p.Tags).JsonMap();
|
||||
cf.Property(p => p.Name).IsNullable(false);
|
||||
cf.Property(p => p.Tags).JsonMap();
|
||||
});
|
||||
|
||||
fsql.Insert(new TestClass("test 1")
|
||||
@ -1043,7 +1054,8 @@ namespace base_entity
|
||||
.Where((a, b) => a.IsDeleted == false)
|
||||
.ToSql((a, b) => new
|
||||
{
|
||||
user = a, group = b
|
||||
user = a,
|
||||
group = b
|
||||
});
|
||||
sql1 = sql1.Replace("INNER JOIN ", "FULL JOIN ");
|
||||
|
||||
@ -1100,7 +1112,8 @@ namespace base_entity
|
||||
groups11 = fsql.Select<UserGroup>().Where(c => c.Id == b.GroupId).ToList(),
|
||||
groups22 = fsql.Select<UserGroup>().Where(c => c.Id == b.GroupId).ToList(c => new
|
||||
{
|
||||
c.Id, c.GroupName,
|
||||
c.Id,
|
||||
c.GroupName,
|
||||
username = b.Username,
|
||||
})
|
||||
}),
|
||||
@ -1805,4 +1818,26 @@ namespace base_entity
|
||||
[Column(Name = "更新时间", CanInsert = false, CanUpdate = true, ServerTime = DateTimeKind.Local)]
|
||||
public DateTime 更新时间 { get; set; }
|
||||
}
|
||||
|
||||
abstract class BaseDataEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public virtual int CategoryId { get; set; }
|
||||
public virtual string Code { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
}
|
||||
[Table(Name = "`FreeSqlTest`.`bdd_1`")]
|
||||
class GoodsData : BaseDataEntity
|
||||
{
|
||||
public override Int32 CategoryId { get; set; }
|
||||
public override string Code { get; set; }
|
||||
public override string Name { get; set; }
|
||||
}
|
||||
class GoodsDataDTO
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public int CategoryId { get; set; }
|
||||
public string GoodsNo { get; set; }
|
||||
public string GoodsName { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -733,6 +733,15 @@
|
||||
<param name="modelBuilder"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlDbContextExtensions.ApplyConfigurationsFromAssembly(FreeSql.ICodeFirst,System.Reflection.Assembly,System.Func{System.Type,System.Boolean})">
|
||||
<summary>
|
||||
根据Assembly扫描所有继承IEntityTypeConfiguration<T>的配置类
|
||||
</summary>
|
||||
<param name="codeFirst"></param>
|
||||
<param name="assembly"></param>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlDbContextExtensions.CreateDbContext(IFreeSql)">
|
||||
<summary>
|
||||
创建普通数据上下文档对象
|
||||
@ -791,5 +800,14 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -1715,7 +1715,12 @@ namespace FreeSql.Internal
|
||||
if (oper2.NodeType == ExpressionType.Parameter)
|
||||
{
|
||||
var oper2Parm = oper2 as ParameterExpression;
|
||||
expStack.Push(exp2.Type.IsAbstract || exp2.Type.IsInterface || exp2.Type.IsAssignableFrom(oper2Parm.Type) ? oper2Parm : Expression.Parameter(exp2.Type, oper2Parm.Name));
|
||||
if (exp2.Type.IsAbstract || exp2.Type.IsInterface || exp2.Type.IsAssignableFrom(oper2Parm.Type))
|
||||
expStack.Push(oper2Parm);
|
||||
else if (oper2Parm.Type.IsAssignableFrom(exp2.Type))
|
||||
expStack.Push(oper2Parm);
|
||||
else
|
||||
expStack.Push(Expression.Parameter(exp2.Type, oper2Parm.Name));
|
||||
}
|
||||
else
|
||||
expStack.Push(oper2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user