0

I have the following code where I am creating a IList that I need to filter by the data in another list called List. The locations list represents the locations a user is allowed to view based on their permissions. I am new to LINQ and am confused with error I get (C# Unknown method "Where(?)" of "System.Ling.IQueryable". I have tried various syntax arrangement using either Contains() and Any() or both to no avail. I feel like it's something very basic that I don't understand about doing this. Here is the code:

 ----- users locations
 using System;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;


 namespace Decking.Models
 {
    public class locations
    {
        [Key]
        public string org_id { get; set; }
    }
 }

 ///////// here is the view model

 using System.ComponentModel.DataAnnotations;
 using System;

 namespace Decking.Models
 {

    public class InventoryViewModel
    {        

        [Key]
        public int id { get; set; }
        public DateTime metric_dt { get; set; }
        public int? item_id { get; set; }
        public int? loc_type_id { get; set; }
        public string trlr_nbr { get; set; }
        public string user_id { get; set; }
        public string org_id { get; set; }
        public Double numerator { get; set; }       

        //these are the child entities
        [UIHint("ClientItem")]
        public ItemViewModel Items
        {
           get;
           set;
        }

        [UIHint("ClientLocTypes")]
        public LocTypesViewModel LocTypes
        {
           get;
           set;
        }

        [UIHint("ClientOrgsByUser")]
        public OrgsByUserViewModel OrgsByUser
        {
           get;
           set;            
        }

    }
 }
 ///////// code to populate the view model

 public IList<InventoryViewModel> GetAll(List<locations> locs)
 {     
  IList<InventoryViewModel> result = new List<InventoryViewModel>();

     result = entities.inventory.Select(inventory => new
 InventoryViewModel
    {

        id = inventory.id,
        metric_dt = inventory.metric_dt,
        item_id = inventory.item_id,
        loc_type_id = inventory.loc_type_id,
        trlr_nbr = inventory.trlr_nbr,
        org_id = inventory.org_id,
        numerator = inventory.numerator,
        user_id = inventory.user_id,

        Items = new ItemViewModel()
        {
            item_id = inventory.items.item_id,
            item_desc = inventory.items.item_desc,
        },

        LocTypes = new LocTypesViewModel()
        {
            loc_type_id = inventory.loc_types.loc_type_id,
            loc_desc = inventory.loc_types.loc_desc,
        },

        OrgsByUser = new OrgsByUserViewModel()
        {
            user_id = inventory.user_id,
            //mgr_emp_nbr = inventory.mgr,
            org_id = inventory.org_id,

        },
 }).Where(e => e.metric_dt == DateTime.Today  && e.org_id

        ==locs.Any(o=>o.org_id)) // this doesn't work

 //}).Where(e => e.metric_dt == DateTime.Today  && e.org_id == "SGF") //  

        this works
 .ToList();

   return result;
}

Any help you can provide would be greatly appreciated! Thank so much! 
1
  • try locs.Any(o=>o.org_id != null)) Commented Mar 6, 2017 at 16:45

1 Answer 1

2

The problem is in e.org_id == locs.Any(o=>o.org_id). As I can see in your working example, your org_id is a string.

I guess what you are trying to do is .Where(e => e.metric_dt == DateTime.Today && locs.Any(o=>o.org_id == e.org_id))

Sign up to request clarification or add additional context in comments.

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.