locked
How to filter when using the load extension method on a DBSet? RRS feed

  • Question

  • I hope I phrased the question correctly.

    I want to do something like this:

    context.Events.Where(d => d.EventDT > "05/01/2011").Load();
    

    But apparently comparison operators are not allowed in this situation or my lambda expression is incorrect.

    I am new to EF and C#.  This is for a Windows Forms application so my next step would be:

     

    this.eventsBindingSource.DataSource = context.Events.Local.ToBindingList();
    

     


    WhiskeyRomeoLima
    Thursday, January 26, 2012 12:00 AM

Answers

  • > I want to do something like this:context.Events.Where(d => d.EventDT > "05/01/2011").Load();But apparently comparison operators are not allowed


    try using the following

    var dt = DateTime.Parse("05/01/2011");
    var res = context.Events.Where(e => e.EventDT > dt).ToList();
    new DataGridView { Dock = DockStyle.Fill, Parent = this, DataSource = res };
    ...
    
    

     
    Thursday, January 26, 2012 12:31 AM

All replies

  • > I want to do something like this:context.Events.Where(d => d.EventDT > "05/01/2011").Load();But apparently comparison operators are not allowed


    try using the following

    var dt = DateTime.Parse("05/01/2011");
    var res = context.Events.Where(e => e.EventDT > dt).ToList();
    new DataGridView { Dock = DockStyle.Fill, Parent = this, DataSource = res };
    ...
    
    

     
    Thursday, January 26, 2012 12:31 AM
  • Thanks for the reply:  var dt = DateTime.Parse("05/01/2011"); is all I needed. 

    ToList doesn't work in a Windows Application if you need it to be bindable list where you can add records.

    This why the next step is:

    this.eventsBindingSource.DataSource = context.Events.Local.ToBindingList();


    WhiskeyRomeoLima
    Thursday, January 26, 2012 1:26 AM