Ejemplo n.º 1
0
        public IQueryable <T> All <T>() where T : class, new()
        {
            if (_options.Contains(SimpleRepositoryOptions.RunMigrations))
            {
                Migrate <T>();
            }

            var qry = new Query <T>(_provider);

            return(qry);
        }
Ejemplo n.º 2
0
 public SimpleRepository(IDataProvider provider, SimpleRepositoryOptions options)
 {
     _provider = provider;
     _options  = options;
     if (_options.Contains(SimpleRepositoryOptions.RunMigrations))
     {
         migrated = new List <Type>();
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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));
        }