I made a simple implementation using EF 6 in Database first Mode (SQL Server 208 R2) . The main objective of this test was to see if the system would have memory issues using EF. After the creation of the Model I used EF 6.x EntityObjecct Generator to create the objects. The database is pretty simple: You create Companies and Users, then you add Users in Company. I created 1000 Companies and 10000 users, after that I used the following code to add all users to all companies:
var query = (from x in db.ACCESS_USER
select x).ToList();
var query1 = (from y in db.COMPANY
select y).ToList();
foreach (var item in query1)
{
foreach (var user in query)
{
ACCESS_USERSINCOMPANY acComp = new ACCESS_USERSINCOMPANY();
acComp.COMPANYID = item.COMPANYID;
acComp.USERID = user.USERID;
acComp.CREATE_DATE = DateTime.Now;
db.AddToACCESS_USERSINCOMPANY(acComp);
db.SaveChanges();
}
}
When I run this code the memory starts to grow and in about 2 min my computer run out of memory. I made one test Running de GC manually and the memory issue got way, but my speed decreased drastically. Any Ideas?