泛型查询报错 返回

SqlSugar 沟通中
4 689
该叫什么 wall 发布于1个月前
悬赏:0 飞吻

System.NullReferenceException: 未将对象引用设置到对象的实例。

02:26:44:459    在 SqlSugar.SqlBuilderProvider.GetTranslationColumnName(String propertyName)

02:26:44:459    在 SqlSugar.QueryBuilder.<>c__DisplayClass280_1.<GetSelectValueByExpression>b__3(KeyValuePair`2 it)

02:26:44:459    在 System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

02:26:44:459    在 System.String.Join(String separator, IEnumerable`1 values)

02:26:44:459    在 SqlSugar.QueryBuilder.GetSelectValueByExpression()

02:26:44:459    在 SqlSugar.QueryBuilder.get_GetSelectValue()

02:26:44:459    在 SqlSugar.SqlServerQueryBuilder.GetSelect(Boolean isFirst, Boolean isTop)

02:26:44:459    在 SqlSugar.SqlServerQueryBuilder._ToSqlString()

02:26:44:459    在 SqlSugar.SqlServerQueryBuilder.ToSqlString()

02:26:44:459    在 SqlSugar.QueryableProvider`1._ToSql()

02:26:44:459    在 SqlSugar.QueryableProvider`1._ToList[TResult]()

02:26:44:459    在 SqlSugar.QueryableProvider`1.ToList()


源码位置:

public virtual string GetSelectValueByExpression()

        {

            var expression = this.SelectValue as Expression;

            string result = string.Empty;

            if (this.IgnoreColumns != null && this.IgnoreColumns.Any())

            {

                var expArray = GetExpressionValue(expression, this.SelectType).GetResultArray()

                    .Where(it=>

                      !this.IgnoreColumns.Any(z=>it.Contains(Builder.GetTranslationColumnName(z)))

                    ).ToArray();

                result =string.Join(",", expArray);

            }


查询代码:

var r = queryable.Select(x => new T { ID = x.ID, Name = x.Name });

var list = r.ToList();


实体:

/// <summary>

/// 角色

/// </summary>

[Serializable()]

[SugarTable("RBAC_Roles")]

public class RBAC_RoleModel : EHS_AbstractModel

{

    [SugarColumn(ColumnName = "RName")]

    public new string Name { get; set; }


    /// <summary>

    /// 角色名称

    /// </summary>

    public string RName { get; set; }


    /// <summary>

    /// 角色中文名称

    /// </summary>

    public string CN_RName { get; set; }


    /// <summary>

    /// 备注

    /// </summary>

    public string Remark { get; set; }


    /// <summary>

    /// 是否启用

    /// </summary>

    public bool IsEnabled { get; set; }


    /// <summary>

    /// 排序

    /// </summary>

    public int SortID { get; set; }


    [SugarColumn(IsIgnore = true)]

    public new DateTime? CreationDate { get; set; } = DateTime.Now;


    [SugarColumn(IsIgnore = true)]

    public new string CreationBy { get; set; }


    [SugarColumn(IsIgnore = true)]

    public new DateTime? LastUpdateDate { get; set; } = DateTime.Now;


    [SugarColumn(IsIgnore = true)]

    public new string LastUpdateBy { get; set; }


热忱回答4

  • fate sta fate sta VIP0
    1个月前

    https://www.donet5.com/Home/Doc?typeId=2366


    局部代码看不出问题需要提供完整的DEMO,按模版。 删掉OBJ和BIN打包上传。 

    0 回复
  • wall wall VIP0
    1个月前

    @fate sta:IgnoreColumns是包括哪些字段,就是里面有空的,会去数据库取字段吗?其他的表都正常,这个表没有Name字段,有RName字段,但是即使 new T{}这样也会报一样的错,demo还在整理。

    0 回复
  • wall wall VIP0
    1个月前

    是不是不支持泛型啊,UpdateColumns也更新不到:

    var rows = client.Updateable(entity).UpdateColumns(t => new { entity.Name }).ExecuteCommand();

    13:39:10:517 EHS_SqlSugarConfig: [  47] [<GetClient>b__7_0] (5) DEBUG - SQL执行: UPDATE [EMS_Documents]  SET

    13:39:10:517              WHERE [ID]=@ID

    13:39:10:517 EHS_SqlSugarConfig: [  51] [<GetClient>b__7_0] (5) DEBUG - 参数: [@Const0='二站'],[@ID=1061]

    13:39:10:517 EHS_SqlSugarConfig: [  57] [<GetClient>b__7_1] (5) ERROR - SQL执行错误: 关键字 'WHERE' 附近有语法错误。


    0 回复
  • fate sta fate sta VIP0
    1个月前

    https://www.donet5.com/Home/Doc?typeId=2366


    局部代码看不出问题需要提供完整的DEMO,按模版。 删掉OBJ和BIN打包上传。 



    0 回复