disadvantages of using IQueryable !

2019-08-17 14:45发布

Is there are any performance issues related to using IQueryable ?
Besides, if I use a cursor instead of using IQueryable (is that better) .
IQueryable vs IEnumerable vs IList ?
I use MongoDB as my database . Thank you

2条回答
家丑人穷心不美
2楼-- · 2019-08-17 15:20

I don't know how the MongoDB C# binding works, but describe how it usually works:

When using IQueryable an expression tree is constructed, then translated into a format the database can understand and then executed in the database-server.

This typically has a small overhead(construct expression tree and translate it) compared to directly writing queries in the format the database understands.

With IEnumerable delegates are used, instead of expressions. It needs to iterate over the complete dataset and then filters using Linq-To-Objects. This is much slower.

查看更多
我只想做你的唯一
3楼-- · 2019-08-17 15:24

Those are just different interfaces, and as interfaces doesn't contain any implementation it doesn't matter for performance which you use.

When you loop over the values the enumerator of the actual class will be used, regardless of which interface you use to access it.

查看更多
登录 后发表回答