What does it mean to be Composable?

.net entity-framework

Question

I'm now reading Larry Tenny and Zeeshan Hirani's book EF4 Recipes. Throughout reading the book, I often saw the phrase "Composable" and had a basic understanding of what it meant, but I was unable to pinpoint its particular meaning.

I was curious as to the precise definition and what qualifies (for example) a function as "Composable" or not.

Check this FAQ for additional information. It's quite close to the context in the book (look for the term "Composable" on the page; there's just one).

I'm not sure what this sentence means in the following passage from the book, which is on 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.

1
14
12/20/2010 12:18:48 AM

Accepted Answer

Composability in this context refers to the ibility to modify the query.

EF queries may be built rather easily. Therefore, you may alter a query:

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);

Because the final query is composed of the elements assembled in the code above, all of this work will be completed on the database server.

But WCF Data Services are far more constrained. You can order and project, but not order based on a projection. Therefore, even if it might be modified and rearranged to work, the code above will not function.

9
12/20/2010 3:39:27 PM

Popular Answer

It alludes to something known as Functions defined by models.

In essence, these MDFs are defined in your EDMX, and then you may "assemble" these inquiries in your LINQ expression.

If, for instance, you had a scalar UDF in your database that returned a person's age, you might map it in your conceptual model by doing the following:

var results = from person in ctx.People
              where GetAge(person) > 35 // GetAge is a UDF mapped in your EDMX
              select person;

There is an article here that goes into greater detail about it.

Although I haven't used them much, I think they have certain restrictions (you can't utilize Table-Valued Functions; only Scalar).

HTH



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow