Starcounter
HomeDownloadDocsCommunity
2.3.1
2.3.1
  • 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
    • 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
      • External HTTP Calls
      • WebSocket
      • Avoiding URI conflicts
      • TCP Sockets
      • UDP Sockets
    • Publishing Apps
    • Working with Starcounter
      • Release Channels
      • 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
  • Object Identity
  • Primary Keys and Foreign Keys
  • Retrieving from Object Identity
  1. Guides
  2. Database

Object Identity and Object References

PreviousData manipulationNextQuerying with SQL

Last updated 7 years ago

Introduction

In Starcounter, an object reference uses an implicit foreign key to an implicit primary key called ObjectId as well as allowing natural keys and public keys to exist and be joined on when needed.

Object Identity

Each object has a ObjectNo and ObjectID property that can be accessed using SQL or the extension methods Object.GetObjectNo() and Object.GetObjectID().

ObjectNo is a unique ulong that can be treated as a primary key. The value becomes available when a database object is created, and is never changed.

ObjectID is a string representation of ObjectNo. It's friendly for sending over the Internet. For example, ObjectID for ObjectNo=40023 is "JxX". ObjectID may contain [A-Za-z0-9-_] characters. Since string comparison in SQL is case insensitive, SQL queries using ObjectID may return more than one result.

Primary Keys and Foreign Keys

As each object already has a unique key in ObjectNo, we recommend adding other keys when you need them, such as public keys that are meant to be exposed to the end user. Objects should be referenced using an object reference rather than by a foreign key except if there is a clear need for natural key referencing.

Retrieving from Object Identity

Objects are retrieved from identity with Db.FromId. It handles both ObjectID and ObjectNo.

A common use is in handlers like this where Person is a database object:

Handle.GET("PersonList/{?}", (string objectId) =>
{
    return new PersonPage()
    {
        Data = Db.FromId<Person>(objectId)
    };
});

There are four overloads of Db.FromId:

T Db.FromId<T>(string base64Id);
T Db.FromId<T>(ulong id);
IObjectView FromId(ulong id);
IObjectView FromId(string base64Id);
URL Base64