为了简化,我将剥离背后的业务规则:
我正在从 WCF 获取数据并填写网格。在后台,我正在检查记录是否已经存在,如果不存在 - 我正在通过 EF 将其添加到表中。一切都很好并且响应迅速,直到涉及到 EF 的操作。代码如下所示:
var ds = client.GetInfo(id,cb_TrackMembers_StartDate.Checked ? dtp_StartDate.Value
: (DateTime?)null,
cb_EndDate.Checked
? dtp_EndDate.Value
: (DateTime?)null,
cb_CompletedOnly.Checked);
DataTable tables = ds.Tables["Table1"];
async_fillgridwithdatatable(gv_source, tables);
private void async_fillgridwithdatatable(DataGridView grid, DataTable table)
{
MethodInvoker action = delegate
{
grid.Rows.Clear();
var existing = db.GetMemberList();
foreach (DataRow row in table.Rows)
{
var username = row["Q51_1"].ToString();
if (!existing.Contains(username))
{
MyDirHelper ldap = new MyDirHelper(username, "");
int acclvl = ldap.GetAccessLevel();
tbl_Member newMember = new tbl_Member
{
username = username,
first_name = row["Q9_1"].ToString(),
last_name = row["Q9_2"].ToString(),
.
.
.
id_accesslevel = db.DB_GetMemberAutoAccessLevelIDByLDAPAccessLevel(acclvl),
created_on = DateTime.Now,
created_by = db.GetUser(E_Username).id_user,
modified_by = db.GetUser(E_Username).id_user,
modified_on = DateTime.Now
};
db.InsertIntoMembersEntity(newMember);
if (newMember.id_accesslevel != 1)
{
if (newMember.id_accesslevel != null)
{
mail_sendWelcome(newMember.email, newMember.id_accesslevel.Value);
db.UpdateMemberWelcomeMailSentDate(newMember.id_member, DateTime.Now);
}
}
}
else
{
tbl_Member existingMember = db.GetMemberByLogin(username);
existingMember.first_name = row["Q9_1"].ToString();
existingMember.last_name = row["Q9_2"].ToString();
.
.
.
existingMember.modified_by = db.GetUser(E_Username).id_user;
existingMember.modified_on = DateTime.Now;
db.Save();
}
grid.Rows.Add(username);
}
};
grid.BeginInvoke(action);
}
有什么方法可以提高这里的响应能力吗?