简体   繁体   中英

c# Mvc Entity Framework issue with WHERE clause and Boolean values

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();
var workerRecords =
    (from oe in context.tbl_Company_Workers 
    where w.WorkerRoleID.HasValue && w.WorkerRoleID == 3
    select oe).ToList();

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();

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();
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM