protected T FindOrCreate <T>(Expression <Func <T, bool> > pred, bool returnExisting) where T : class, new() { var entity = EntityFactory.Find(pred, EntitySource); if (entity != null) { if (!returnExisting) { return(null); } EntityFactory.Attach(entity); return(entity); } else { return(EntityFactory.Create <T>()); } }