0

I am using this code to create a table:

db2.CreateTable<Phrase>();

Here's the Phrase class:

public class Phrase : IPhrase
{
    [PrimaryKey, NotNull]
    public string PhraseId { get; set; }
    public int PhraseNum { get; set; }
    public int CategoryId { get; set; }
    public string English { get; set; }
    public string Romaji { get; set; }
}

When I hover over the CreateTable it gives a message saying that it creates any specified indexes on the columns of the table. It uses a schema automatically generated from the specified type.

Does anyone know how I could for example create an index on the PhraseNum?

2 Answers 2

1

For a single property-based index add an IndexedAttribute:

public class Package
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [Indexed]
    public string Name { get; set; }
    ~~~~

For a multiple field index, use the Name and Order parameters within the IndexedAttribute:

public class Package
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [Indexed(Name = "SecondaryIndex", Order = 1)]
    public string Name { get; set; }
    [Indexed(Name = "SecondaryIndex", Order = 2)]
    public string PackageName { get; set; }
    ~~~
Sign up to request clarification or add additional context in comments.

Comments

1

Try

  [Indexed]
  public int PhraseNum { get; set; }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.