Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

sql - EF Core: Is it possible to index properties within a complex type which is within another complex type of which I'll query?

In EF Core, is it possible to index properties within a complex type which is within another complex type which I plan on querying and where the indexes will ultimately matter?

If I have an object which I want to optimize its queries, and a property within it is a complex type, can I index the properties within this complex type in reference to the outer object's queries?

Here is an example of the two objects, the one as a property within the other:

public class AuditableEntity
{
    public int Id { get; set; }
    
    [Required]
    public DateTime CreatedOn { get; set; }

    [Required]
    public string CreatedBy { get; set; }
}

and

public class NotificationItem : IAuditableEntityComposition
{
    public AuditableEntity AuditableEntity { get; set; }
}

So, for instance I'd like to query on

NotificationItem.AuditableEntity.CreatedOn

I'd like to have an optimized query for AuditableEntity.CreatedOn when there is a collection of some sort that is referencing this, such as a list of NotificationItem that needs to query on CreatedOn.


I'm trying to use fluent syntax. For instance:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<NotificationItem>()
        .HasIndex(ni => ni.AuditableEntity.CreatedOn);
}

The nested ni.AuditableEntity.CreatedOn doesn't work.

If you have any questions, need more information, or I did something wrong, please let me know and I'll do my best to fix it.

question from:https://stackoverflow.com/questions/66057810/ef-core-is-it-possible-to-index-properties-within-a-complex-type-which-is-withi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...