Compartir a través de


Expressions ("M" to SQL Mapping)

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

Microsoft code name “M”->SQL can translate most “M” expressions including operators (*, /, +, -), queries ("from person in People where person.Age >= 21"), constants and initializers ("astring", { 1, 2, 3 }), as well as things like member access and function calls (person.Age).

These expressions can be used in several different contexts, including computed values, constraints, default values, and initializers. This section does not discuss those contexts except where expressions behave differently or do not work. For more information about those contexts, see the Extents (M to SQL Mapping) and Computed Values (M to SQL Mapping) sections.

“M” supports a wide range of expressions over a wide range of types, but “M”->SQL only supports expressions that return scalars, entities, and collections of scalars or entities (the same set of types that are supported by extent -> table translation).

Composition

Expressions are composable, which means that the result of one expression can be used in another expression. This documentation discusses the way in which individual expressions are turned into SQL, but only calls out particularly interesting compositions.

For example,

A + B -> A + B

A.Count -> LEN(A)

This code refers to any “M” expression that can fit into A and B, so if the “M” expression MyString.Count + 10, is translated to SQL as ( LEN(MyString) ) + 10.

Query expressions are similarly composed, as show in the following example.

A | B -> A UNION B

This expression take the SQL query expression for A and the SQL query expression for B and place them into those slots. So if you say "Cats | Dogs", it is translated into "(SELECT * FROM Cats) UNION (SELECT * FROM Dogs)".

In This Section