Modelon Solutions

A fresh take on your ideas

Entity Framework 6.1

Published by

on

Another day and another small update for Entity Framework… this time with something I really needed about 1 month ago.

I had an entity that was declared like this :

        public class Sale
        {
                [Key]
                public int Id { get; set; }

                public virtual int Product_Id { get; set; }
                [ForeignKey("Product_Id")]
                public virtual Product Product { get; set; }

                public virtual int Year { get; set; }

                //other stuff
        }

The problem is, I have foreign keys which generate indexes, but I did a lot of searching by the year, which is an integer and doesn’t get a index by default (unless you start messing with the schema manually or via migrations).

This new update allows me to add the Index attribute as follows, and then magic occurs.

        [Index]
        public virtual int Year { get; set; }

A great feature to have in Entity Framework, get more details on the official blog post !

Leave a comment