Starcounter
HomeDownloadDocsCommunity
2.3.2
2.3.2
  • Starcounter Documentation
  • Getting Started
  • Starcounter
    • Collapsing the Stack
      • Complexity and Scalability Tradeoff
      • The Future of Micro-Services
      • 10 Benefits of Collapsing the Stack
    • Integrated Database and Web Server
  • Hello World - Tutorial
    • Create a Database Class
    • Create a Real Time UI
    • First Interactive UI
    • Computed Properties
    • Expense Tracker
    • Cancel and Delete
    • The Next Step
  • Guides
    • Database
      • Database Classes
      • Data manipulation
      • Object Identity and Object References
      • Querying with SQL
      • Data Types
      • Relations
      • Inheritance
      • Sharing data
      • Database Configuration
      • Comparing Database Objects
      • Referential Integrity and Constraints
    • SQL
      • Identifiers
      • Path Expressions
      • Data operators
      • Joins
      • Aggregates
      • Comparisons and Logical Operators
      • Sorting
      • Fetch
      • Offset Key
      • Indexes
      • Literals
      • Query Plan Hints
      • Reserved words
      • Query for Database Classes
      • SQL Isolation Between Applications
    • Transactions
      • Short-Running Transactions
      • Long running transactions
      • Using Transactions
      • Running Background Jobs
      • Commit Hooks
      • Post-commit hooks
    • Typed JSON
      • JSON-by-example
      • Code-Behind
      • Data Bindings
      • Callback Methods
      • Responding with JSON
      • Accepting JSON in Requests
      • Primitive Arrays and Single Value Types
      • Typed JSON Internals
    • Blendable Web Apps
      • Starcounter MVVM
      • Palindrom
      • Client-Side Stack
      • Sessions
      • HTML Views
      • App Shell
      • Web Components
      • View Attaching
      • View Composing
      • HTML Compositions
      • HTML Views Blending Guidelines
      • Avoiding CSS conflicts
      • Debugging
    • Network
      • HTTP
      • Internal Self Calls
      • Middleware
      • Anonymous or Substitute Handlers
      • URL Aliases and Redirects
      • Network Gateway
      • Static File Server
      • WebSocket
      • Avoiding URI conflicts
      • TCP Sockets
      • UDP Sockets
    • Publishing Apps
    • Working with Starcounter
      • Release Channels
      • Installation
      • Starting and Stopping Apps
      • Administrator Web UI
      • Star CLI
      • StarAdmin CLI
      • StarDump CLI
      • Working in Visual Studio
      • Error Log
      • Using HTTPS on NGINX
      • Using HTTPS on IIS
      • Run Starcounter in Production
      • Weaver
      • Investigating App Crashes
      • Configuration Structure
      • Database Refactoring
      • Using Unload/Reload to Modify Database Schema
      • Kernel Questions and Answers
      • Log Files
  • Cookbook
    • Attach an HTTP Request to an Existing Long-Running Transaction
    • Cookie-Based Authentication
    • Timestamp on Object Creation
    • Creating Strongly Typed JSON Collections
    • Migrating From 2.2 to 2.3+
    • Multiple Pages
    • Icons
    • Proposed Project Structure
    • Acceptance Testing with Selenium
    • Requesting a User to Authenticate
    • How to delete unused tables and columns
Powered by GitBook
On this page
  • Introduction
  • Wildcards
  • Cast Operation
  1. Guides
  2. SQL

Path Expressions

Introduction

In Starcounter SQL you can refer to any property of a database classes as long as there is a path from the database class specified in the FROM clause to that property.

A path expression is an arbitrary long sequence of identifiers separated by dots. The first identifier in the sequence should be an alias to an database class defined in the FROM clause of the SELECT statement. The following identifiers except the last one should have object references as return values. The last identifier may return any supported datatype. For example:

SELECT e.Manager.Department.Location.Street FROM Employee e

If an identifier in a path expression returns null then the complete path expression will return null.

Path expression can also be used in WHERE and ORDER BY clauses:

SELECT e FROM Employee e WHERE e.Manager.Department.Name = 'sales'
SELECT e FROM Employee e ORDER BY e.Manager.Department.Profit

Wildcards

You can use a wildcard (*) to select all properties of a database class:

SELECT * FROM Employee
SELECT e.* FROM Employee e

The above queries return all the properties of the Employee objects, while the below query returns references to the Employee objects themselves.

SELECT e FROM Employee e

Cast Operation

In some path expressions you need to cast the type of a property.

For example, consider a data model like this:

[Database]
public class Person
{
  public Person Father { get; set; }
}

[Database]
public class Employee : Person
{
  public Employee Manager { get; set; }
}

If you want to select the manager of each person's father whenever such manager exists, then this is incorrect since Father is of type Person and Person has no Manager property:

Incorrect
SELECT p.Father.Manager FROM Person p

However, if you cast Father to type Employee then you can continue the path expression with Manager:

Correct
SELECT CAST(p.Father AS Employee).Manager FROM Person p

If the object reference Father for some objects in the extent Person is not of type, or subtype of Employee , then this object reference can't be cast to Employee and the operation returns null.

The cast operation only supports casts between different types of database objects and not between different value types.

PreviousIdentifiersNextData operators

Last updated 7 years ago