Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi . I want to write this t-sql in LINQ

SQL
select * from [Ticket] t where t.TicketStatusId in
(
    select k.TicketStatusId  from [TreeOfKnowledgeData] k
)


please help me .
Posted

IN = Contains in Linq

http://www.dotnetperls.com/list-contains[^]

but, your sql query is obviously look like this

http://stackoverflow.com/questions/25355004/simple-example-subquery-linq[^]

I hope this will help you :)
 
Share this answer
 
v2
Think of it! You don't need to use IN, you have to use Join[^]! Why? It's quite obvious: above statement get only that tickets which TicketStatusId field is equal to TreeOfKnowledgeDataTicketStatusId.

C#
var qry = from ticket in Tickets 
     join knowdata in TreeOfKnowledgeDatas on ticket.TicketStatusId equals knowdata.TicketStatusId
    select ticket;


If you would like to get data from both "tables", try this:
C#
var qry = from ticket in Tickets 
     join knowdata in TreeOfKnowledgeDatas on ticket.TicketStatusId equals knowdata.TicketStatusId
    select new
    {
         statid = ticket.TicketStatusId, 
         kbd    = knowdata.AnotherField
    };
 
Share this answer
 
v3

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