Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Composable exactly mean?

I'm currently reading through EF4 Recipes, the book, by Larry Tenny and Zeeshan Hirani. I came across the word "Composable" a lot, during reading the book, & had a general sense about what the word means, but no exact definition though.

I was wondering what the exact definition is, & what makes (say for eg) a function "Composable" or not?

For more context, Check this FAQ (Look for the word "Composable" on the page, there's only one) which is pretty similar to the same context on the book..

Here's is a paragraph where I feel confused about what it means (from the book page 397):

The parameters for model defined functions don’t show direction. There are no ‘out’ parameters, only implied ‘in’ parameters. The reason for this is that model defined functions are composable and can be used as part of LINQ queries. This prevents them from returning values in output parameters.

like image 573
Shady M. Najib Avatar asked Dec 19 '10 22:12

Shady M. Najib


1 Answers

Composability, in this sense, means that you can further refine the query.

EF queries are very composable. So you can take a query and change it:

var q = Context.MyStuff;
q = q.Where(s => s.IsGood);
var r = from s in q select new { Id = s.Id, Description = s.Description };
r = r.OrderBy(s => s.Description);
r = r.Take(100);

All this work will be done on the DB server, because the final query is composed of its parts, built up in the code above.

WCF Data Services, OTOH, are much more limited. You can project, and you can order, but you can't order on the projection. So the code above won't work, although it could be tweaked and re-ordered to work.

like image 116
Craig Stuntz Avatar answered Oct 04 '22 04:10

Craig Stuntz