子查询中跨库问题怎么解决 返回

SqlSugar
2 210

源码: 

int loginUserId = 18297;

var source = Db.Queryable<Mb_Video, users_company>((a, b) => new object[] {

                JoinType.Inner,a.UserId == b.ID

            }).AS<users_company>("www_dzsc_com.dbo.users_company")

            .WhereIF(true, whereExpression)

            .Select((a, b) => new Mod_VideoView

            {

                Id=a.Id,

                SumVideoCommentCount = SqlFunc.Subqueryable<Mb_VideoComment>().Where(s => s.VideoID == a.Id).Count(),

                SumCollectCount = SqlFunc.MappingColumn(default(int), $"(select count(0) from dzsc_search.dbo.Video_TopClickRecords s where s.UserId={loginUserId} )")

            }).MergeTable();

问题一:

 SumVideoCommentCount = SqlFunc.Subqueryable<XXX.dbo.Mb_VideoComment>().Where(s => s.VideoID == a.Id).Count(),

当中的XXX.dbo.Mb_VideoComment与主表的数据库不一样,如何关联XXX.dbo数据库?

问题二:

 SqlFunc.MappingColumn(default(int), $"(select count(0) from dzsc_search.dbo.Video_TopClickRecords s where s.UserId={loginUserId} )"),

当中加了参数loginUserId,但是报错:“Index and length must refer to a location within the string. (Parameter 'length')”

MergeTable()就失败了,是什么原因呢?

热忱回答2

  • 问题一、SUBQUERY暂时不支持外面的AS 下个版本将支持


    问题二、

    SQL从外面拼好传进来

     SqlFunc.MappingColumn(default(int), SQL),

    0 回复
  • @fate stay night:谢谢大佬

    0 回复