Click here to Skip to main content
15,070,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Could someone please suggest if
there is any way to write below SQL query using LINQ Query(VB.Net)


SQL
Select Count(Distinct(User_ID)) from tbl_CTRL where Req_ID = "R1" AND User_ID in ('001','002','005','007')



TABLE: "tbl_CTRL"

User_ID || Req_ID
001 || R1
002 || R2
003 || R1
004 || R1
005 || R2
006 || R1
007 || R3

What I have tried:


Posted
Updated 19-Apr-21 6:37am
v2

1 solution

Simple:
VB.NET
Dim ids As New List(Of String)
ids.Add("001")
ids.Add("002")
ids.Add("005")
ids.Add("007")

Dim records = From item in YourContext.YourTable
              Where ids.Contains(item.User_ID)
              Select item
Introduction to LINQ - Visual Basic | Microsoft Docs[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900