Is it possible to have PrimaryKey and Index attributes for multiple realm properties (item)?

Asked 2 years ago, Updated 2 years ago, 57 views

Would it be possible to attach PrimaryKey or Indexed attributes to multiple properties (items) to the class (table) as shown below?If possible, I would appreciate it if you could tell me the syntax.
I look forward to your kind cooperation.

cThe image is to add PrimaryKey to code1 and code2 and Indexed to code3 and code4.

class MasterTable:RealmObject
{
     [PrimaryKey]
    public int code1 {get;set;}
    public string code2 {get;set;}

    Indexed
    public string code3 {get;set;}
    public string code4 {get;set;}

    public string firstname {get;set;}

}

realm

2022-09-29 21:28

1 Answers

Only one PrimaryKey can be specified per type of object.

Indexed can be multiple properties.

For example,

class MasterTable:RealmObject
{
     [PrimaryKey]
    public int code1 {get;set;}
    public string code2 {get;set;}

    Indexed
    public string code3 {get;set;}
    Indexed
    public string code4 {get;set;}

    public string firstname {get;set;}

}

You can write like this.

If you want to represent a primary key in multiple properties, for example, you can create a property that combines code1 and code2 (implementing it to contain values that combine code1 and code2 yourself) and specify that property as the primary key.


2022-09-29 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.