views:

44

answers:

2
 public class ErrorLogModel
{

    public int UnitID { get; set; }
    public string Address { get; set; }
    public IList<HardwareLogModel> _Hardware { get; set; }

}
  public  class SPLHardwareLogModel
{
    public Guid HardwareID { get; set; }
    public string HardwareDesc { get; set; }
    public string HardwareStatus { get; set; }
    public string ErroLogCode { get; set; }
    public string ErroLogDescription { get; set; }
    public DateTime? ErroLogDate { get; set; }
}

If i want to use expression where clause for ErrorLogModel where HardwareID=100

Can any body help me?

ErrorLogModel.Where((SPLHardwareLogModel a)=>a.ErroLogCode=='10001');

A: 

Hey,

Wouldn't it be:

ErrorLogModel.Where(i => i.SPLHardwareLogModels.FirstOrDefault(j => j.ErrorLogCode = '10001') != null);

That way, it finds the error log model and parses the subcollection, looking for the existence of an object. That's if you want to select the errorlogmodel object. Is that the case?

If this happens to answer your question, please mark it as the answer, which will help up your answer rate...

HTH.

Brian
A: 

Hard to read the question - not sure if this helps, but I'll post it anyway.

List<SPLHardwareLogModel> result = myErrorLogModel._Hardware
    .OfType<SPLHardwareLogModel>()
    .Where(a => a.HardwareID == 100)
    .Where(a => a.ErroLogCode == '10001')
    .ToList();
David B