Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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# 是否按任意顺序检查两列中是否存在两个值?_C#_Sql Server_Linq_Visual Studio - Fatal编程技术网

C# 是否按任意顺序检查两列中是否存在两个值?

C# 是否按任意顺序检查两列中是否存在两个值?,c#,sql-server,linq,visual-studio,C#,Sql Server,Linq,Visual Studio,我在数据库中有一个表;它有三列。 第一个(Friends_Id)是(int)主键,其他的是(User_1和User_2)nvarchar(50) 每个(用户1和用户2)发生一次。 (用户_1和用户_2)中值的顺序并不重要。这意味着值“A”和“B”可以通过以下任一方式放入此表中: ------------------------------ | Friends_Id | User_1| User_2 | ------------------------------ | 37 |

我在数据库中有一个表;它有三列。 第一个(Friends_Id)是(int)主键,其他的是(User_1和User_2)nvarchar(50)

每个(用户1和用户2)发生一次。
(用户_1和用户_2)中值的顺序并不重要。这意味着值“A”和“B”可以通过以下任一方式放入此表中:

------------------------------
| Friends_Id | User_1| User_2 |
------------------------------
|    37      |   A   |   B    |
------------------------------
或:

当然,“A”可以多次出现,但其值不是“B”。
“B”也是如此;它可以与“A”以外的值一起出现

问题是:如何在C#中使用LINQ to实体检查(“A”、“B”)或(“B”、“A”)的存在。

查询必须回答以下问题:在列(用户1、用户2)中,是否有“A”和“B”的出现顺序(“A”、“B”)或(“B”、“A”)。

类似的情况可能会出现:

int count = (from row in table
where (row.user_1 == "A" && row.user_2 == "B") || (row.user_1 == "B" && row.user_2 == "A"))
.Count();

if(count > 0)
{
    // your code
}
或者更好的方法是使用
Any()


返回Convert.ToBoolean(repository.Where(x=>(x.User_1==“A”和&x.User_2==“B”)|(x.User_1==“B”和&x.User_2==“A”).Count()
int count = (from row in table
where (row.user_1 == "A" && row.user_2 == "B") || (row.user_1 == "B" && row.user_2 == "A"))
.Count();

if(count > 0)
{
    // your code
}
if(context.table.Any(r => (r.User_1 == "A" && r.User_2 == "B") || (r.User_1 == "B" && r.User_2 == "A")))
{
    // your code
}