C# SQL实体框架通过包含列选项的继承索引

C# SQL实体框架通过包含列选项的继承索引,c#,sql,entity-framework,indexing,C#,Sql,Entity Framework,Indexing,我今天来是因为我的表演问题。我现在正在研究索引,但是,我找不到一种合适的方法在类继承中放置索引。。我有一段代码: public abstract class BaseEntityWithId { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } = new Guid(); [Required] public DateTimeOf

我今天来是因为我的表演问题。我现在正在研究索引,但是,我找不到一种合适的方法在类继承中放置索引。。我有一段代码:

public abstract class BaseEntityWithId
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid Id { get; set; } = new Guid();

    [Required]
    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;

    public DateTimeOffset? UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
}

[Table("AccountExampleEntity")]
public class AccountExampleEntity : BaseEntityWithId
{
    public string UserName { get; set; }

    public string Password { get; set; }

    public Guid UserId { get; set; }

    public Guid DeviceId { get; set; }

    [ForeignKey("UserId")]
    public virtual UserEntity User { get; set; }

    [ForeignKey("DeviceId")]
    public virtual DeviceEntity Device { get; set; }
}
根据此代码,Azure创建了一个警告并告诉我以下内容:

  • 索引类型
    • 非聚集
  • 模式
    • [dbo]
  • 桌子
    • [会计示例实体]
  • 索引键列
    • [用户ID]
  • 包含列
    • [创建数据],[设备ID],[更新数据]
因此,基于此,我想创建一个索引,我将共享到这4个属性上,但是,我找不到正确的方法来实现它。。我找到的唯一方法是通过“隐藏继承的成员”来重新创建属性。代码如下:

[Table("AccountExampleEntity")]
public class AccountExampleEntity : BaseEntityWithId
{
    public string UserName { get; set; }

    public string Password { get; set; }

    [Index("AccountExampleIndex", Order = 1)]
    public Guid UserId { get; set; }

    [Index("AccountExampleIndex", Order = 2)]
    public Guid DeviceId { get; set; }    

    [Index("AccountExampleIndex", Order = 3)]
    public new DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;

    [Index("AccountExampleIndex", Order = 4)]
    public new DateTimeOffset? UpdatedAt { get; set; } = DateTimeOffset.UtcNow;

    [ForeignKey("UserId")]
    public virtual UserEntity User { get; set; }

    [ForeignKey("DeviceId")]
    public virtual DeviceEntity Device { get; set; }
}
这样做对不对?上次检查时,我在stackoverflow和EF6上找不到任何内容,但今天我再次进入它,需要知道:)

谢谢你的帮助