I'm trying to create a single compound index, but I do not know how to do this in Microsoft.EntityFrameworkCore.SQLite
, I'm used to working only with Doctrine
and Hibernate
and I'm totally lost.
This is my template class:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
namespace Test.Entity
{
public class Project
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
private int id;
[Required]
private bool shared;
[Required, MaxLength(64)]
private String name;
private Project parent;
[ForeignKey("id")]
private ICollection<Project> searchable;
public bool Shared
{
get { return shared; }
set { shared = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public Project Parent
{
get { return parent; }
set { parent = value; }
}
public int Id
{
get { return id; }
set { id = value; }
}
public ICollection<Project> Searchable
{
get { return searchable; }
set { searchable = value; }
}
}
}
This is my method in my context class
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<Project>().HasIndex(r => new { r.Name, r.Parent}).IsUnique();
}