0

This is my tables definition :

Ticket 
 -------------------------------
|ID        int              PK  |
|Paid      varchar(50)          |
 -------------------------------

TicketRow
 ----------------------------------
|ID            int              PK |
|TicketID_FK   int                 |
|SHtimeID_FK   int                 |
 ----------------------------------

And this is my sql query :

select SHtimeID_FK,count(*) as cnt 
from dbo.TicketRow as tr inner join dbo.Ticket as t on tr.TicketID_FK=t.ID
where t.Paid='ok'
group by SHtimeID_FK
having count(*)>1

How should i convert this query to a Linq query?

UPDATE :

I try this query but i don't know how should i complete my query !

MelliConcertEntities db = new MelliConcertEntities();
var s = (from x in db.TicketRow
                         where x.Ticket.Paid == "ok"
                         select x).GroupBy(???);
1
  • 1
    Have you already tried anything? How is your context set? Give us something to let us help you! Commented Oct 16, 2013 at 23:53

1 Answer 1

1
db.TicketRow
    .Where( tr => tr.Ticket.Paid == "ok" )
    .GroupBy( tr => tr.SHtimeID_FK )
    .Where( g => g.Count() > 1 )
    .Select( g => 
        new { 
            SHtimeID_FK = g.Key, 
            cnt = g.Count() } );

or

var s = from tr in db.TicketRow
        where tr.Ticket.Paid == "ok"
        group tr by tr.SHtimeID_FK into g
        where g.Count() > 1
        select new {
            SHtimeID_FK = g.Key,
            cnt = g.Count()
        };
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.