c# - 带别名的 Linq

标签 c# linq alias

我在 C# 中有以下行:

var name = (from x in db.authors
                    where fullName == "Jean Paul Olvera"
                    orderby x.surname
                    select new { x.id_author, fullName= String.Concat(x.name," ", x.surname) });

我的问题是我想在我的 where 子句中使用别名,但我不能,'fullName' 显示为未声明。

最佳答案

您可以使用 let 来创建中间值:

var name = (from x in db.authors
            let fullName = x.name + " " + x.surname
            where fullName == "Jean Paul Olvera"
            orderby x.surname
            select new { x.id_author, fullName });

关于c# - 带别名的 Linq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15906967/

相关文章:

sql-server - 我可以使用 LINQ 对 SQL Server 中的 IQueryable 进行联接吗?

c# - 如何在运行时在 IEnumerable<T> 上创建动态 Select?

C#:如何为类创建 "aliases"

c# - 奇怪的 TimeSpan.ToString 输出

c# - 继承 System.Exception 之外的内置异常类

c# - "Count()"上的 "Take()"之后的 "IQueryable"返回错误结果?

tcp - H2 数据库函数别名访问另一个函数

amazon-web-services - AWS 证书在浏览器中不安全

c# - 将 .txt 文件放入 DataGridView

c# - 将 XML XDocument 增量写入磁盘,保留有效的 XML