0

I'm using Entity Framework 6 and vb.net 2017. I have 2 cases when I need to create a query step by step :

query = (From t in context.myobj1s select t)

if (condition1) then 
    query = query.where(Function(t2) t2.value1 < 5)
If (condition2) then 
    query = query.where(Function(t2) t2.value2 > 120)

query.tolist

and

query = (From t in context.myobj1s.Local select t)

if (condition1) then 
    query = query.where(Function(t2) t2.value1 < 5)
If (condition2) then 
    query = query.where(Function(t2) t2.value2 > 120)

Mybindingsource.Datasource = query.tolist

My question is: how should I declare query in each situation:

 Dim query as IEnumerable(of myobj1)

or

 Dim query as IQueryable(of myobj1)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
antoni
  • 1
  • 6
  • 4
    Possible duplicate of [What is the difference between IQueryable and IEnumerable?](https://stackoverflow.com/questions/252785/what-is-the-difference-between-iqueryablet-and-ienumerablet), esp. [this answer](https://stackoverflow.com/a/23359554/861716). – Gert Arnold Apr 15 '19 at 07:16

1 Answers1

0

IQueryable(of myobj1) is preferable if you are going to use database related methods. For example, the Include(...) method is implemented based on IQueryable.

The IQueryable is extends from IEnumerable

public interface IQueryable<out T> : System.Collections.Generic.IEnumerable<out T>, System.Linq.IQueryable
Kazbek
  • 182
  • 11