Query and method calls using the specified method.

Source: Internet
Author: User

Query and method calls using the specified method.

 

Generally, a query object that implements IQueryable <T> is required when you use linq to query.

 public class DataA<T> : IQueryable<T> {....}

  

Then pass

 var q = from c in new DataA<int>() where c > 0 select new { a = c.ToString() };

Query, and use IQueryProvider to collect user input expressions for processing.

However, the query itself is only concerned with the availability of linqmethod (Select, Where...) on the query object .....).

Define a generic object as follows:

public class Data<T> {        public Data<TResult> Select< TResult>(   Expression<Func<T, TResult>> selector) {            return new Data<TResult>();        }        public Data<T> Where (  Expression<Func<T,bool>> f) {            return this;        }    }

You only need to ensure that the Data has the same instance method as the linq method, (Select, Where ...),

We can still use the same linq syntax for queries:

var q = from c in new Data<int>() where c > 0 select new { a = c.ToString() };

Conclusion: The linq query syntax is irrelevant to the type of the query object. It only checks whether the query object has the same name and method signature (instance method or extension method ).

IQueryable and IQueryProvider are not required in the linq query.

By the way, I personally think that it is best not to use IQueryable in orm, which may easily cause method pollution, and the syntax of the linq query is fixed and cannot be expanded or restricted.

It is better to use various query methods directly in Orm to make it more flexible.

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.