Namespaces (Entity SQL)

Entity SQL introduces namespaces to avoid name conflicts for global identifiers such as type names, entity sets, functions, and so on. The namespace support in Entity SQL is similar to the namespace support in the .NET Framework.

Entity SQL provides two forms of the USING clause: qualified namespaces (where a shorter alias is provided for the namespace), and unqualified namespaces, as illustrated in the following example:

USING System.Data;

USING tsql = System.Data;

Name Resolution Rules

If an identifier cannot be resolved in the local scopes, Entity SQL tries to locate the name in the global scopes (the namespaces). Entity SQL first tries to match the identifier (prefix) with one of the qualified namespaces. If there is a match, Entity SQL tries to resolve the rest of the identifier in the specified namespace. If no match is found, an exception is thrown.

Next, Entity SQL tries to search all unqualified namespaces (specified in the prolog) for the identifier. If the identifier can be located in exactly one namespace, that location is returned. If more than one namespace has a match for that identifier, an exception is thrown. If no namespace can be identified for the identifier, Entity SQL passes the name onto the next outward scope (the DbCommand or DbConnection object), as illustrated in the following example:

SELECT TREAT(p AS NamespaceName.Employee)
FROM ContainerName.Person AS p
WHERE p IS OF (NamespaceName.Employee)

Differences from the .NET Framework

In the .NET Framework, you can use partially qualified namespaces. Entity SQL does not allow this.


Queries are expressed through ADO.NET DbCommand objects. DbCommand objects can be built over DbConnection objects. Namespaces can also be specified as part of the DbCommand and DbConnection objects. If Entity SQL cannot resolve an identifier within the query itself, the external namespaces are probed (based on similar rules).

See Also


Entity SQL Reference
Entity SQL Overview