[英]Linq to get the data from 2 columns having same name of 2 different tables using "Joins" in .net?
public async Task<List<string>> EmailSearch(string filter)
{
try
{
var x = await _context.tbl_Account.Where(x => x.Email.Contains(filter) && x.IsActive == true).Select(x => x.Email).ToListAsync();
return x;
}
catch(Exception)
{
throw;
}
}
In the above code I was getting the data from one table but now I want data from another table also using "Joins" with Linq for condition like in above code, in .NET Core.在上面的代码中,我从一个表中获取数据,但现在我希望另一个表中的数据也使用 Linq 的“联接”,以实现与上述代码类似的条件,在 .NET 核心中。
The table names are tbl_Account and tbl_Contacts both table have a column which is named as Email (same column name).表名是 tbl_Account 和 tbl_Contacts 两个表都有一个名为 Email 的列(相同的列名)。
-> Thanks in advance... -> 在此先感谢...
You create two queries and then union them, since you're just using a string as a result, you should be ok, try something like this...您创建两个查询,然后将它们合并,因为您只是使用字符串作为结果,您应该没问题,尝试这样的事情......
public async Task<List<string>> EmailSearch(string filter)
{
try
{
var x = _context.tbl_Account
.Where(x => x.Email.Contains(filter) && x.IsActive == true)
.Select(x => x.Email);
var y = _context.tbl_Contacts
.Where(x => x.Email.Contains(filter) && x.IsActive == true)
.Select(x => x.Email);
var z = await x.Union(y).ToListAsync()
return z;
}
catch(Exception)
{
throw;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.