问题描述
我已经注意到NPoco(或PetaPoco)的工作方式存在巨大差异,具体取决于您使用LINQ时调用的函数.
I've noticed a huge difference in how NPoco (or PetaPoco) works depending on which function you call when you are using LINQ.
例如,比较Fetch()和Query()两者似乎都做相同的事情:
For instance compare Fetch() which Query() which both appear to do the same thing:
A :Fetch<EntryImage>().Where(t => t.EntryType == type && t.EntryID == entryID);
B :Query<EntryImage>().Where(t => t.EntryType == type && t.EntryID == entryID);
A 返回表中的每一行(10,000+),然后过滤客户端.
A returns every row in the table (10,000+) and then filters client side.
B 仅返回我期望的一个行.
B returns just the one row I'm expecting.
我发现这种行为非常危险-在没有真正注意的情况下编写性能很差的代码非常容易.这是预期的行为吗?如果这是正常行为,是否有任何方法可以获取以这种方式工作的方法列表,因此我可以避免在可能的情况下使用它们?
I find this behavior is quite dangerous - it would be very easy to write very badly performing code without really evening noticing. Is this expected behavior? If this is normal behavior, is there any way to get a list of methods which work this way, so I can avoid using them where possible?
推荐答案
这是NPoco的预期行为.
This is expected behavior for NPoco.
根据来源:
提取 返回列表.
Fetch returns a list.
/// <summary>
/// Fetch all objects of type T from the database using the conventions or configuration on the type T.
/// Caution: This will retrieve ALL objects in the table
/// </summary>
List<T> Fetch<T>();
查询 返回IQueryProviderWithIncludes(类似于IQueryable
)
/// <summary>
/// Entry point for LINQ queries
/// </summary>
IQueryProviderWithIncludes<T> Query<T>();
这篇关于NPoco/PetaPoco Fetch()获取所有数据然后过滤客户端是否正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!