[ 
https://issues.apache.org/jira/browse/GROOVY-8258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16089499#comment-16089499
 ] 

Daniel Sun commented on GROOVY-8258:
------------------------------------

LINQ will translate LINQ statement into method calls, which is like stream API 
of Java 8. LINQ-like DSL is just a syntactic sugar, the backend is the stream 
API.

{code:java}
// C# LINQ method calls
IQueryable<Product> source = database.Products;
var results = source.Where(product => product.ReorderLevel > 20)
                    .Select(product => new
                        {
                            ProductName = string.Concat("@", 
product.ProductName),
                            UnitPrice = product.UnitPrice
                        });
{code}


> Create a LINQ-like DSL
> ----------------------
>
>                 Key: GROOVY-8258
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8258
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>
> *Pojos:*
> {code:java}
> class Category {
>    String name
>    List<Article> articles
> }
> class Article {
>   String name
>   Integer voteCount
>   String categoryName
> }
> {code}
> *Example1:*
> {code:java}
> linq { // return an Iterator<Map<String, Object>>
>     from c of categories
>     join a of articles on a.categoryName == c.name // join
>     where c.name == 'Groovy'
>     orderBy a.voteCount desc // order by
>     limit 100 offset 50 // pagination
>     select { // create a map, its keys: articleName, voteNum, categoryName
>         articleName = a.name
>         a.voteCount 
>         categoryName = c.name
>     }
> }
> {code}
> *Example2:*
> {code:java}
> linq { // return an Iterator<Map<String, Object>>
>     from c of categories
>     join a of {
>         from tempA of articles
>         where tempA.voteCount > 10
>         select tempA
>     } on a.categoryName == c.name // join
>     where c.name == 'Groovy'
>     orderBy a.voteCount desc // order by
>     limit 100 offset 50 // pagination
>     select { // create a map, its keys: articleName, voteNum, categoryName
>         articleName = a.name
>         a.voteCount 
>         categoryName = c.name
>     }
> }
> {code}
> *Example3:*
> {code:java}
> linq { // return an Iterator<Article>
>     from c of categories
>     from a of c.articles  // another join
>     where c.name == 'Groovy'
>     orderBy a.voteCount desc // order by
>     select Article { // create an Article instance
>         a.name
>         a.voteCount 
>         categoryName = c.name
>     }
> }
> {code}
> *TO BE CONTINUED...*



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to