Solved

How to write linq for the below sql query

Posted on 2014-10-03
1
109 Views
Last Modified: 2016-02-15
I am trying to write linq to sql query and have just started with linq.

How can I write linq for the following query

select * from SP_FORM where SP_FORM_ID in ( 
select SP_FORM_ID from SP_FORM_PAGES group by SP_FORM_ID having count(*)>1
)

Open in new window


Any help will be appreciated.

Thanks.
0
Comment
Question by:developer2012
1 Comment
 
LVL 11

Accepted Solution

by:
louisfr earned 500 total points
ID: 40360131
If all the names are the same in the code, the equivalent Linq would be
from form in SP_FORM
where (from page in SP_FORM_PAGES
       group page by page.SP_FORM_ID into g
       where g.Count() > 1
       select g.Key).Contains(form.SP_FORM_ID)
select item;

Open in new window

A join might be more efficient.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question