hi. if you are sure that your qry is correct then obvious reason would be that the status value satisfies all the 10 records. Have you checked the currentstatus field in the resulting records?
Yes. The currentstatus field returns those even which does not satisfy the where condition. Running it in debug mode, query1 has the following value before I hit the query1.ToList() line at the end:
{SELECT [t0].[TrackrsQueueId] AS [RequestId], [t0].[ProjectNo],
(CASE
WHEN 0 = 1 THEN NULL
ELSE [t0].[SubId]
END) AS [SubId], [t1].[AgencyCode] AS [Agency], [t1].[DRNumber], [t0].[RequestType], CONVERT(NChar(1),[t0].[QueueStatus]) AS [CurrentStatus], [t0].[ModifiedDate] AS [LastActivityDate], [t0].[SubmittedBy] AS [RequestedBy]
FROM [dbo].[TrackrsQueue] AS [t0]
INNER JOIN [dbo].[Trackrs] AS [t1] ON [t0].[ProjectNo] = [t1].[ProjectNo]
}
Should the where be included already in this statement?
tinac99
Member
74 Points
137 Posts
linqtosql result always returns 10 even with where condition
Nov 15, 2012 05:37 PM|LINK
Hi,
I have the following script:
List<uoPublishingItem> results;
using (TrackrsDataContext dc = new TrackrsDataContext())
{
IQueryable<uoPublishingItem> query1 = (from q in dc.TrackrsQueues
join t in dc.Trackrs on q.ProjectNo equals t.ProjectNo
select new uoPublishingItem
{
RequestId = q.TrackrsQueueId,
ProjectNo = q.ProjectNo,
SubId = q.SubId == null ? (int?)null : q.SubId,
Agency = t.AgencyCode,
DRNumber = t.DRNumber,
RequestType = q.RequestType,
CurrentStatus = q.QueueStatus,
LastActivityDate = q.ModifiedDate,
RequestedBy = q.SubmittedBy
});
if(!String.IsNullOrEmpty(DropDownListStatus.SelectedValue))
{
query1.Where(q => q.CurrentStatus == Convert.ToChar(DropDownListStatus.SelectedValue));
}
results = query1.ToList<uoPublishingItem>();
How come the results always come up with 10 records, even after adding the where condition - it should only come up with one record?
I appreciate your input!
Thanks,
tinac99
rishinet
Member
104 Points
22 Posts
Re: linqtosql result always returns 10 even with where condition
Nov 15, 2012 07:27 PM|LINK
hi. if you are sure that your qry is correct then obvious reason would be that the status value satisfies all the 10 records. Have you checked the currentstatus field in the resulting records?
tinac99
Member
74 Points
137 Posts
Re: linqtosql result always returns 10 even with where condition
Nov 15, 2012 10:36 PM|LINK
Yes. The currentstatus field returns those even which does not satisfy the where condition. Running it in debug mode, query1 has the following value before I hit the query1.ToList() line at the end:
{SELECT [t0].[TrackrsQueueId] AS [RequestId], [t0].[ProjectNo],
(CASE
WHEN 0 = 1 THEN NULL
ELSE [t0].[SubId]
END) AS [SubId], [t1].[AgencyCode] AS [Agency], [t1].[DRNumber], [t0].[RequestType], CONVERT(NChar(1),[t0].[QueueStatus]) AS [CurrentStatus], [t0].[ModifiedDate] AS [LastActivityDate], [t0].[SubmittedBy] AS [RequestedBy]
FROM [dbo].[TrackrsQueue] AS [t0]
INNER JOIN [dbo].[Trackrs] AS [t1] ON [t0].[ProjectNo] = [t1].[ProjectNo]
}
Should the where be included already in this statement?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: linqtosql result always returns 10 even with where condition
Nov 16, 2012 08:31 AM|LINK
Hi,
This won't return you one value because you have to re-assign again to itself:
if(!String.IsNullOrEmpty(DropDownListStatus.SelectedValue)) { query1 = query1.Where(q => q.CurrentStatus == Convert.ToChar(DropDownListStatus.SelectedValue)); }