Is it acceptable to do this? First try to the add the entity. If the add fails, it doesn't matter because that means the entity already exists?
Or is there a more elegant/easy solution?
EntityFrameworkEntities dal = EntityDataModelHelper.GetEntityDataModel();
try
{
dal.AddToXXXXXX(xxxxxxx);
}
catch
{
}
try
{
dal.SaveChanges();
return true;
}
catch
{
return false;
}
OK I shortened it to...
EntityFrameworkEntities dal = EntityDataModelHelper.GetEntityDataModel();
if(xxxxxxx.ID == 0)
{
dal.AddToXXXXXX(xxxxxxx);
}
try
{
dal.SaveChanges();
return true;
}
catch
{
return false;
}