I am cloning user's information, security, departments and several other tables of information to create a new user with same setup. This information is being displayed through several DGV's. When I use a normal linq to context:
var x = (from ctx in context.UserInfo
where ctx.UserID == userID
select ctx);
The information display almost instantaneously, but does not display the added user, unless I call SaveChanges()
which I'm trying not to do.
Then I switched to using local linq:
context.UserInfo.Load();
var x = (from ctx in context.UserInfo.Local
where ctx.UserID == userID
select ctx);
However, several tables I am querying have over 30k entries and the .Local call significantly slows down the process of displaying the information. From what I have researched this happens due to validation tracking.
Then I tried using the change tracker:
context.UserInfo.Load();
var x = (from ctx in context.ChangeTracker.Entries<UserInfo>()
where ctx.Entity.UserID == userID && ctx.State == EntityState.Unchanged ||
ctx.State == Entity.State.Added || ctx.State == EntityState.Modified
select ctx.Entity)
This gave the same poor performance as the Local call.
Is there anyway to quickly display added objects and not display deleted objects without having to call Local or is there a way to speed up Local?
I have done a fair amount of research and worked on this problems for a few days, trying to figure it out on my own, but I'm going around in circles now.
I have thought about creating a copy of the context, before changes are made. Saving the changes as they happen, and if the user decides to cancel out the creation of the cloned user, calling up the original context and saving it, to restore the original context, but I would consider that a last resort.
The project is being done in C# .net 4.5 and Entity Framework 5.0 on a Windows Form
EDIT:
To give more code on how query's are implemented:
I have a loadData() method that initializes the data I will be using.
public void loadData()
{
var x = (from ctx in context.UserInfo
select ctx).ToList();
}
I believe this would do the same thing as the above code
public void loadData()
{
context.UserInfo.load();
}
Then the query is called: This is fast query, but does not show context changes
public List<UserInfo> getUserInfo()
{
var user = (from ctx in context.UserInfo
where ctx.UserID == userID
select ctx).ToList();
return user;
}
This query is slow, but shows changes
public List<UserInfo> getUserInfo()
{
var user = (from ctx in context.UserInfo.Local
where ctx.UserID == userID
select ctx).ToList();
return user;
}