What is first class mechanism in EF?

120 views Asked by At

In the sample data for EF Datastore in the MusicStore sample project for ASP.NET MVC 6.

There is a comment

"// TODO [EF] This may be replaced by a first class mechanism in EF"

https://github.com/aspnet/MusicStore/blob/master/src/MusicStore.Spa/Models/SampleData.cs

What is first class machanism? I know there is codefirst, but does not seem to be related to that, and could not find anything on first class.

The code below which the comment refers too.

        // TODO [EF] This may be replaced by a first class mechanism in EF
    private static async Task AddOrUpdateAsync<TEntity>(
        IServiceProvider serviceProvider,
        Func<TEntity, object> propertyToMatch, IEnumerable<TEntity> entities)
        where TEntity : class
    {
        // Query in a separate context so that we can attach existing entities as modified
        List<TEntity> existingData;
        using (var db = serviceProvider.GetService<MusicStoreContext>())
        {
            existingData = db.Set<TEntity>().ToList();
        }

        using (var db = serviceProvider.GetService<MusicStoreContext>())
        {
            foreach (var item in entities)
            {
                db.Entry(item).State = existingData.Any(g => propertyToMatch(g).Equals(propertyToMatch(item)))
                    ? EntityState.Modified
                    : EntityState.Added;
            }

            await db.SaveChangesAsync();
        }
    }
0

There are 0 answers