Tuesday, March 16, 2010

LINQ to Object : Querying Non- IEnumerable collections


Below is an example of accessing EventlofEntityCollection, if I need to filter EventlogEntityCollect using LINQ I just need to mention object type in my collect after from clause in LINQ statement.

Instead of:

var ev = from e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;

Use:
var ev = from EventLogEntry e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;


Example:
EventLog elog = new EventLog();
            /* Tell Which type of log we need to access
            1. System
            2. Security
            3. Application
            */
            elog.Log = "Application";
           //Filter and Select Eventlog Entries Using LINQ
            var ev = from EventLogEntry e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;

No comments:

Post a Comment

Followers

Search This Blog