如何在LINQ SQL WHERE子句中使用Concat字符串?

时间:2015-12-16 02:06:44

标签: sql-server linq

我想在linq中连接到哪里,但我在网上找不到答案,所以在这个网站上询问。这是我的问题。

在mysql中:

  

从表中选择*,其中concat(field1,'',field2)='field1   FIELD2' ;

如何在linq sql中转换它?

2 个答案:

答案 0 :(得分:3)

您应该能够通过以下方式轻松完成此任务(我正在使用NorthWind数据库和流畅的Linq-to-SQL):

Employees.Where (e => e.FirstName + " " + e.LastName == "Nancy Davolio")

答案 1 :(得分:0)

string x = "field1 field2";

List<Tuple<string, string>> tupleList = new List<Tuple<string, string>>();
tupleList.Add(new Tuple<string, string>("field1", "field2"));
tupleList.Add(new Tuple<string, string>("field1", "field3"));
tupleList.Add(new Tuple<string, string>("field1", "field4"));
tupleList.Add(new Tuple<string, string>("field1", "field5"));
tupleList.Add(new Tuple<string, string>("field1", "field6"));
tupleList.Add(new Tuple<string, string>("field1", "field2"));

var results = tupleList.Where(l => String.Concat(l.Item1, " ", l.Item2) == x);

results.Dump();