PrimaryKey class

Primary key annotation for composite primary keys (multiple columns).

Use this annotation on the entity class to define a composite primary key when you need multiple columns to form the primary key. The columns must exist as fields in the entity.

For single-field primary keys, use @Id on the field instead.

Note: You cannot use both @Id and @PrimaryKey in the same entity. A build error will be thrown if both are used together.

Example:

@Entity(tableName: 'order_items')
@PrimaryKey(columns: ['order_id', 'product_id'])
class OrderItemEntity {
  int orderId;
  int productId;
  int quantity;
}

Constructors

PrimaryKey({required List<String> columns, String? name})
const

Properties

columns List<String>
List of column names that form the composite primary key
final
hashCode int
The hash code for this object.
no setterinherited
name String?
Optional name for the primary key constraint
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited