Why should IQueryProvider implementations throw NotSupportedExceptions?

Searching the web, we can find plentiful examples of various ORMs (nHibernate, EF, LinqToSql, etc.) that implement but don’t actually support the full IQueryable<T> interface, throwing NotSupportedExceptions when they encounter something they don’t like, such as LinqToSql and SkipWhile. My question is this: why do ORM providers opt to throw a NotSupportedException instead of letting certain query operators (that do not translate well or at all to the target data source) trip a query execution and then let Linq to objects handle the rest?

I understand that some heavy physical resource usage could occur as a result, but if IQueryable<T> instances were truly swappable, would we not be better off?

One of the purpose of the IQueryable<T> interface is also to allow differed execution of the query, i.e., the functions applied to the collection are not actually applied but converted internally, in the case of LINQ to SQL for example, in an SQL query (a string).

If there is no way of expressing the given function in the source, then you can’t support the operation, and you better have the programmer know that by throwing the NotSupportedException. He might then decide to switch to a specific data structure and carry on from there, but at least he knows what he’s doing.

3

Well, because

  1. You would lose control of the query process, and
  2. You would get an unexpected, and inaccurate, result.

The NotSupportedException is there so that you, the developer, can be notified of the unsupported feature. You can then re-work your query in some way to get the result you want, without using the unsupported feature.

8

I think the main reason is that such behavior could have very unexpected performance. Namely, if you tried to skip over most of some table, the query would need to load most of the table (or at least the relevant columns).

When the choice is between something that is unexpected and reporting error that can be easily fixed (by adding AsEnumerable() before the TakeWhile()), I think it makes sense to choose the latter.

If you don’t like this, you could create your own IQueryable wrapper, that behaves exactly the way you want: if the underlying IQueryable throws NotSupportedException, call the equivalent method from LINQ to Objects (by using AsEnumerable()).

5

Because of it’s complexity. If query throws NotSupportedException that probably means you query is extremely complex. And as such, it would be really hard to separate what can be run over DB and what must be done in-memory. In simplest way, you just fetch the whole table or maybe half of the DB, thanks to joined records. And you must be crazy to think that is good idea, especially when it happens without you knowing. Implementing such detection algorithm would be quite complex, probably even more complex than implementing query feature itself.

Also, implementing IQueryable is quite complex in itself (as proven by NHibernate devs), so they probably haven’t had time to implement this specific feature of whole complex query system.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật