Tuesday, May 28, 2019

get all period ending dates from the beginning of the year to end date


//get all period ending dates from the beginning of the year to end date
                    var endDate = productivitySearchDto.ToDate;
                    var dates = Enumerable.Range(1, endDate.DayOfYear)
                        .Select(n => new DateTime(endDate.Year,1,1).AddDays(n))
                        .Where(date => date.DayOfWeek == DayOfWeek.Saturday)
                        .ToList();

Friday, May 10, 2019

Entity framework performance issue, saveChanges is very slow

I put entity.saveChanges within the foreach because it is a large list, around 3k records and it was taking around 10-15 minutes

solution : 

Entityframework 6.xx

reference 
https://stackoverflow.com/questions/21272763/entity-framework-performance-issue-savechanges-is-very-slow


using (var context = new CustomerContext())
{
    context.Configuration.AutoDetectChangesEnabled = false;

    // A loop to add all your new entities

    context.SaveChanges();
}




Entityframework core
make this line as false, remember it has its own effect if your working connected entity
it worked for me because i working in disconnected entities model
db.ChangeTracker.AutoDetectChangesEnabled = false;