Beispiel #1
0
        public static IQueryable <T> Read <T>(Type type, Expression <Func <T, bool> > where, ISave repo)
        {
            var tType = typeof(T);
            var set   = BaseCruds.GetDbSet(repo, type);
            var q     = Queryable.Where <T>((IQueryable <T>)set, where);

            return(q);
        }
Beispiel #2
0
        public static object Find(string typeString, long id, out ISave repo)
        {
            var type = GetModelType(typeString);
            var set  = BaseCruds.GetDbSet(type, out repo);
            var q    = Queryable.Where <IInt64Key>((IQueryable <IInt64Key>)set, b => b.Id == id);

            return(q.FirstOrDefault());
        }
Beispiel #3
0
        public static void Create(IContentModel input)
        {
            var db       = GetRepo();
            var IQueable = BaseCruds.GetDbSet(db, BaseIContentModelType);
            var method   = BaseCruds.GetMethod(db, BaseIContentModelType, "Add", out var IContent);

            method.Invoke(IContent, new object[1] {
                input
            });
            db.SaveChanges();
        }
Beispiel #4
0
        public static void Delete <T>(ISave repo, T model) where T : class, IInt64Key
        {
            var tType     = typeof(T);
            var modelType = model.GetType().GetRealType();

            if (tType != modelType)
            {
                Delete(model as object, repo);
                return;
            }
            if (repo == null)
            {
                var id = model.Id;
                model = Find <T>(id, out repo);
            }
            var set = BaseCruds.GetDbSet <T>(repo) as DbSet <T>;

            set.Remove(model);
            repo.SaveChanges();
        }