Is there a general method to check whether a property define supported by a Linq provider, especially OData?

后端 未结 2 1292
暖寄归人
暖寄归人 2021-02-20 05:09

I successfully ran the following statement with the NorthWind.sdf in LinqPad:

from s in Shippers
    select new
{
    s.ShipperID,
    s.CompanyName,      
    C         


        
2条回答
  •  花落未央
    2021-02-20 05:41

    Unfortunately there is no general programmatic way of checking whether a LINQ provider will be able to translate any given query. Typically you'll have to resort to documentation or (to be sure) actually try out the queries as you are doing.

    Different providers may, however, provide some mechanism of generating some representation for the query, which you may be able to use to check whether the query would work without having to execute it.

    In the OData client case, you can invoke .ToString() on the query, and it should return a URL if it's able to successfully process the query; otherwise it will return an error message that looks similar to 'Error translating Linq expression to URI: ...' (the actual error message may change depending on the user language, but it will definitely not be a valid URI).

提交回复
热议问题