0

can someone please assist me adjust my syntax below. I keep getting an error that says "Error 403 'bool' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)"

var workerRecords =
    from oe in context.tbl_Company_Workers.ToList() 
    where( 
        w => w.WorkerRoleID.HasValue && w.WorkerRoleID == 3
    ).ToList();
4
  • 1
    you need a Select clause before your ToList() Commented May 28, 2015 at 9:39
  • @tschmit007 I think where and ToList() is enough to get this work .Please correct me if I'm wrong , I use select if i'm selecting particular properties only .var result = Collection.Where(g=>g.Id >5).ToList() and var result2 = Collection.Where(g=>g.Id>5).Select(h=>h.Id).ToList(); Commented May 28, 2015 at 11:41
  • I think this may return Workers with this filter var workerRecords = context.tbl_Company_Workers.Where(w => w.WorkerRoleID.HasValue && w.WorkerRoleID == 3).ToList(); Commented May 28, 2015 at 11:53
  • @tschmit007 sorry , I was wrong, Linq must definitely need a projection Select to get the data . Commented May 28, 2015 at 12:06

3 Answers 3

1
var workerRecords =
    (from oe in context.tbl_Company_Workers 
    where w.WorkerRoleID.HasValue && w.WorkerRoleID == 3
    select oe).ToList();
Sign up to request clarification or add additional context in comments.

Comments

0

why do you need w.WorkerRoleID.HasValue if you are strictly selecting 3?

var workerRecords =
    (from oe in context.tbl_Company_Workers.ToList() 
    where oe.WorkerRoleID == 3 select oe
    ).ToList();

Comments

0

Please chekc using statements

using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;


/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
 public void MethodName()
   {
    var workerRecords = context.tbl_Company_Workers.where(cw =>     w.WorkerRoleID.HasValue && w.WorkerRoleID.Value == 3).ToList();
    }
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.