public IQueryable <T> All <T>() where T : class, new() { if (_options.Contains(SimpleRepositoryOptions.RunMigrations)) { Migrate <T>(); } var qry = new Query <T>(_provider); return(qry); }
public SimpleRepository(IDataProvider provider, SimpleRepositoryOptions options) { _provider = provider; _options = options; if (_options.Contains(SimpleRepositoryOptions.RunMigrations)) { migrated = new List <Type>(); } }
public bool Exists <T>(Expression <Func <T, bool> > expression) where T : class, new() { if (_options.Contains(SimpleRepositoryOptions.RunMigrations)) { Migrate <T>(); } //return All<T>().Any(expression); var tbl = _provider.FindOrCreateTable <T>(); var qry = new Select(_provider).From(tbl); var constraints = expression.ParseConstraints().ToList(); #region Support SubSonicColumnNameOverrideAttribute foreach (Constraint ct in constraints) { PropertyInfo pi = typeof(T).GetProperties().SingleOrDefault(p => p.Name == ct.ColumnName); if (pi != null) { var columnAttributes = pi.GetCustomAttributes(typeof(SubSonicColumnNameOverrideAttribute), false); if (columnAttributes.Length > 0) { ct.ConstructionFragment = (columnAttributes[0] as SubSonicColumnNameOverrideAttribute).ColumnName; } } } #endregion qry.Constraints = constraints; var list = qry.ToList <T>(); if (list.Count > 0) { return(true); } return(false); }
public bool Exists <T>(Expression <Func <T, bool> > expression) where T : class, new() { if (_options.Contains(SimpleRepositoryOptions.RunMigrations)) { Migrate <T>(); } var qry = new Query <T>(_provider); return(qry.Any(expression)); }