Why not merge the set of existing entities with those to be added? I tested this out and it seems to work- it doesn't account for Deletes though, but you should be able to get the idea:
// get the entities that have been inserted or modified
var projects = myObjectContext.ObjectStateManager.GetObjectStateEntries(
EntityState.Added | EntityState.Modified).Where(
x => x.Entity is Project).Select( x=> (Project) x.Entity);
// get existing entities, exclude those that are being modified
var projects2 = myObjectContext.Projects.Where(
BuildDoesntContainExpression<Project, int>(z => z.ProjectId,
projects.Select(x => x.ProjectId)));
// Union the 2 sets
var projects3 = projects.Union(projects2);
BuildDoesntContainExpression: you can't use contains, and therefore you can't do the inverse, with the EF for some reason, so use this method:
private static Expression<Func<TElement, bool>> BuildDoesntContainExpression<TElement, TValue>(
Expression<Func<TElement, TValue>> valueSelector, IEnumerable<TValue> values)
{
if (null == valueSelector)
{
throw new ArgumentNullException("valueSelector");
}
if (null == values)
{
throw new ArgumentNullException("values");
}
ParameterExpression p = valueSelector.Parameters.Single();
// p => valueSelector(p) == values[0] || valueSelector(p) == ...
if (!values.Any())
{
return e => false;
}
var equals = values.Select(
value => (Expression)Expression.NotEqual(valueSelector.Body, Expression.Constant(value, typeof(TValue))));
var body = equals.Aggregate<Expression>((accumulate, equal) => Expression.And(accumulate, equal));
return Expression.Lambda<Func<TElement, bool>>(body, p);
}