逐步创建查询,我应该使用IEnumerable还是IQueryable?

时间:2019-04-14 16:35:46

标签: vb.net entity-framework-6

我正在使用Entity Framework 6和vb.net2017。当我需要逐步创建查询时,有2种情况:

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

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

我的问题是:在每种情况下如何声明查询:

 Dim query as IEnumerable(of myobj1)

 Dim query as IQueryable(of myobj1)

1 个答案:

答案 0 :(得分:0)

如果要使用数据库相关的方法,最好使用

IQueryable(myobj1的)。例如,Include(...)方法是基于IQueryable实现的。

IQueryable是IEnumerable的扩展

p = figure(title="Cluster Activity",
           plot_width=1200,
           plot_height=700,
           toolbar_location=None)

without = p.square(name="without", ##your filtered data source without names)
with = p.square(name="with", ##your filtered data source with names)

hoverwith = HoverTool(names=["with"],tooltips=TOOLTIPS = [
        ("Usage", "@{usage}%"),
        ("Name", "@name"),
        ("PID", "@pid"),
        ("Command", "@command"),
        ("User", "@user"),
    ])

hoverwithout = HoverTool(names=["without"],tooltips=TOOLTIPS = [
    ("Usage", "@{usage}%"),
    ("PID", "@pid"),
    ("Command", "@command"),
    ("User", "@user"),
])


p.add_tools(hoverwith, hoverwithout)