TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
David Smith
NA
2k
0
Linq transfer to sql
Nov 22 2012 2:22 PM
I need help convert this SQL to Linq below.
SELECT tblService.FilledByID, Count(tblService.ServiceID) AS NumOfServices
FROM tblService INNER JOIN refServiceType ON tblService.ServiceType = refServiceType.ServiceTypeID
WHERE (((DatePart("ww",[ServiceDateStart]))=DatePart("ww",DLookUp("ServiceDate","sysUser"))) AND ((Year([ServiceDateStart]))=Year(DLookUp("ServiceDate","sysUser"))) AND ((tblService.ServiceStatus)<>5 And (tblService.ServiceStatus)<>7))
GROUP BY tblService.FilledByID
HAVING (((tblService.FilledByID) Is Not Null));
I am not getting the same results as the SQL above.
var query= from tblService in DataAccess.SavedServiceRequestTypeList.AsEnumerable()
join refServiceType in DataAccess.refServiceTypeList.AsEnumerable()
on tblService.ServiceTypeID equals refServiceType.ServiceTypeID
orderby tblService.FilledByID
where (tblService.ServiceDateStart.Date == DataAccess.SavedSystemUserList.Select(s => s.ServiceDate.Date).Max() &&
tblService.ServiceDateStart.Year == DataAccess.SavedSystemUserList.Select(s => s.ServiceDate.Year).Max()) &&
(tblService.ServiceStatusID != 5) || (tblService.ServiceStatusID != 7)
group new { tblService, refServiceType } by tblService.FilledByID into g
select new
{
FilledById = g.Key,
NumOfServices = g.Count(s => s.tblService.ServiceId > 0)
};
Reply
Answers (
1
)
Use of CASCADE CONSTRAINTS in SQL
Self Join in SQL