public static TEntity CreateIfNew <TEntity>(this ITable <TEntity> source, Func <TEntity, Expression <Func <TEntity, bool> > > selector, TEntity newItem) where TEntity : class { if (!source.Any(selector(newItem))) { source.InsertOnSubmit(newItem); } return(newItem); }
private static Expression <Func <Version.ValidationResult, bool> > ForOrdersOrProject(ITable <Identity> orderIds, long?projectId) => x => x.OrderId == null && x.ProjectId == null || x.OrderId.HasValue && orderIds.Any(y => y.Id == x.OrderId.Value) || x.ProjectId.HasValue && x.ProjectId == projectId;