コード例 #1
0
        public IQueryable <User> GetProduct([QueryString("UserID")] int?userID)
        {
            var _db = new SystemKnowledgeWebForms.Models.UserContext();
            IQueryable <User> query = _db.Users;

            if (userID.HasValue && userID > 0)
            {
                query = query.Where(p => p.UserID == userID);
            }
            else
            {
                query = null;
            }
            return(query);
        }
        public IQueryable <User> GetProducts([QueryString("id")] int?areaOfKnowledge)
        {
            var _db  = new SystemKnowledgeWebForms.Models.UserContext();
            var _db2 = new SystemKnowledgeWebForms.Models.AreaOfKnowledgeContext();
            IQueryable <User>            query  = _db.Users;
            IQueryable <AreaOfKnowledge> query2 = _db.AreasOfKnowledge;

            if (areaOfKnowledge.HasValue && areaOfKnowledge > 0)
            {
                query2 = query2.Where(k => k.AreaOfKnowledgeID == areaOfKnowledge);

                /* AreaOfKnowledge area = _db.AreasOfKnowledge
                 *  .Where(u => u.AreaOfKnowledgeID == areaOfKnowledge)
                 *  .FirstOrDefault();*/
                query = query.Where(p => p.AreasOfKnowledges.Contains(query2.FirstOrDefault()));
            }
            return(query);
        }