Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;SQL树中的空类型映射;使用实体框架核心3.1.2.0筛选时不为空_C#_Entity Framework Core_Linq To Entities - Fatal编程技术网

C# &引用;SQL树中的空类型映射;使用实体框架核心3.1.2.0筛选时不为空

C# &引用;SQL树中的空类型映射;使用实体框架核心3.1.2.0筛选时不为空,c#,entity-framework-core,linq-to-entities,C#,Entity Framework Core,Linq To Entities,这是我所面临问题的简化版本 我有这个表DbSet\u DbSet其中报告是: public class Report { public string Name { get; set;} // other fields } 目前,我正在检索Name列的不同非空值,如下所示: public async Task<IEnumerable<string>> GetDistinctReportNameAsync() { return = await _db

这是我所面临问题的简化版本

我有这个表
DbSet\u DbSet
其中
报告
是:

public class Report
{
    public string Name { get; set;}
    // other fields
}
目前,我正在检索
Name
列的不同非空值,如下所示:

public async Task<IEnumerable<string>> GetDistinctReportNameAsync()
{
    return = await _dbSet
        .Select(r => r.Name)
        .Where(name => name != null)
        .Distinct()
        .ToListAsync()
}

var nonNullReportNames = await GetDistinctReportNameAsync();
public async Task<IEnumerable<string>> GetDistinctReportTextColumnAsync(string columnName)
{
    var parameterExpr = Expression.Parameter(typeof(Report), "r");
    var expr = Expression.Property(parameterExpr, columnName);
    var lambda = Expression.Lambda(expr, parameterExpr);
    var selectPredicate = (Expression<Func<Report, string>>)lambda;

    return = await _dbSet
        .Select(selectPredicate)
        .Where(value => value != null)
        .Distinct()
        .ToListAsync()
}
var nonNullReportNames = await GetDistinctReportTextColumnAsync(nameof(Report.Name));
但当我在Report上调用
GetDistinctReportTextColumnAsync
时。名称如下:

public async Task<IEnumerable<string>> GetDistinctReportNameAsync()
{
    return = await _dbSet
        .Select(r => r.Name)
        .Where(name => name != null)
        .Distinct()
        .ToListAsync()
}

var nonNullReportNames = await GetDistinctReportNameAsync();
public async Task<IEnumerable<string>> GetDistinctReportTextColumnAsync(string columnName)
{
    var parameterExpr = Expression.Parameter(typeof(Report), "r");
    var expr = Expression.Property(parameterExpr, columnName);
    var lambda = Expression.Lambda(expr, parameterExpr);
    var selectPredicate = (Expression<Func<Report, string>>)lambda;

    return = await _dbSet
        .Select(selectPredicate)
        .Where(value => value != null)
        .Distinct()
        .ToListAsync()
}
var nonNullReportNames = await GetDistinctReportTextColumnAsync(nameof(Report.Name));
我收到这个错误:

{
  "ExceptionType": "InvalidOperationException",
  "Message": "Null TypeMapping in Sql Tree",
  "InnerMessage": ""
}
如果我在
getdistinctreporttextcolumnsync
中注释掉这一行
。其中(value=>value!=null)
,那么我可以毫无问题地获得
Name
的列表

为什么我不能使用
!=空
当使用
表达式时
是我自己构建的,我如何解决这个问题

我的环境如下:

  • 实体框架核心3.1.2.0
  • .Net标准2.1
  • Visual Studio 2019在Windows 10上运行,64位
  • 在Debian 8.3.0-6上运行的PostgreSQL 12.4,64位
我已经看到了,但它是关于使用带有字符串连接的查询的,这与我的问题无关