我做了第一个 SaveChanges 和苍蝇异常 (UpdateException)。我做了第二个 SaveChanges 并再次执行第一个错误。该怎么办
bool isUpdate = false;
var resource = new Resource() { url = tbUrl.Text };
//block1
try
{
context.Resource.AddObject(resource);
context.SaveChanges();
isUpdate = true;
}
catch (UpdateException ex)
{
}
//block2
if (!isUpdate)
{
resource = (from res in context.Resource where res.url == tbUrl.Text select res).First();
context.NameToResourcer.AddObject(new NameToResourcer()
{
id_resource = resource.id,
name = tag
});
context.SaveChanges();//error!
}