简体   繁体   English

Composable究竟意味着什么?

[英]What does Composable exactly mean?

I'm currently reading through EF4 Recipes, the book, by Larry Tenny and Zeeshan Hirani. 我目前正在阅读Larry Tenny和Zeeshan Hirani撰写的EF4食谱。 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): 这是一个段落,我对它的含义感到困惑(来自书页397):

The parameters for model defined functions don't show direction. 模型定义函数的参数不显示方向。 There are no 'out' parameters, only implied 'in' parameters. 没有'out'参数,只隐含'in'参数。 The reason for this is that model defined functions are composable and can be used as part of LINQ queries. 原因是模型定义的函数是可组合的 ,可以用作LINQ查询的一部分。 This prevents them from returning values in output parameters. 这可以防止它们返回输出参数中的值。

Composability, in this sense, means that you can further refine the query. 从这个意义上讲,可组合性意味着您可以进一步优化查询。

EF queries are very composable. EF查询非常易于组合。 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. WCF数据服务OTOH受到更多限制。 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. 所以上面的代码不起作用,虽然它可以调整和重新订购工作。

It's referring to something called Model Defined Functions . 它指的是称为模型定义函数的东西。

Essentially, you define these MDF's in your EDMX, then you can "compose" these queries in your LINQ statement. 基本上,您在EDMX中定义这些MDF,然后您可以在LINQ语句中“组合”这些查询。

For example, say you had a scalar UDF in your DB which returned the age of a person, then you could map it in your conceptual model and do this: 例如,假设您的数据库中有一个标量UDF,它返回了一个人的年龄,那么您可以将其映射到概念模型中并执行以下操作:

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

There is a article here which explains it a bit more. 有一个文章在这里这也解释了它多一点。

I haven't used them much - but i believe it has some limitations (for example you can't use Table-Valued Functions, only Scalar). 我没有太多使用它们 - 但我相信它有一些限制(例如你不能使用表值函数,只能使用标量)。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM