Example #1
0
        public IEnumerable <person> Search(Pagequery page, string faceId, string uuid, string code, string[] tags)
        {
            List <person> list = new List <Repository.person>();

            using (var db = new personrepositoryEntities())
            {
                try
                {
                    Stopwatch sw         = Stopwatch.StartNew();
                    var       tagLink    = GetTagIn(tags);
                    var       persontags = (db.persontags.Where(c => tags.Contains(c.TagName))
                                            .Select(s => new
                    {
                        FaceID = s.FaceID
                    })).Distinct();

                    IQueryable <person> query = null;
                    //if (persontags.Count() > 0)
                    //{
                    query = (from n in db.persons
                             join tag in persontags on n.FaceID equals tag.FaceID
                             select n);
                    //}
                    //else
                    //{
                    //    query = (from n in db.persons
                    //             select n);
                    //}

                    if (!faceId.IsEmpty())
                    {
                        query = query.Where(s => s.FaceID.StartsWith(faceId));
                    }

                    if (!uuid.IsEmpty())
                    {
                        query = query.Where(s => s.UUID.StartsWith(uuid));
                    }

                    if (!code.IsEmpty())
                    {
                        query = query.Where(s => s.Code.StartsWith(code));
                    }

                    page.TotalCount = query.Count();
                    list            = query.Select(n => n).OrderBy(n => n.CreateTime).Skip(page.Offset).Take(page.Pagesize).ToList();

                    sw.Stop();
                    print("查询耗时->" + sw.ElapsedMilliseconds);
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
            }
            return(list);
        }
Example #2
0
        public IEnumerable <person> Search1VN(Pagequery page, string[] faceIds, string[] tags, long validTime)
        {
            List <person> list = new List <Repository.person>();

            using (var db = new personrepositoryEntities())
            {
                try
                {
                    var tagLink = GetTagIn(tags);

                    IEnumerable <string> tagtofaceID = null;
                    if (tags.Length > 0)
                    {
                        tagtofaceID = db.persontags.Where(c => tags.Contains(c.TagName)).Select(s => s.FaceID).Distinct();
                    }

                    IQueryable <person> query = db.persons.Where(f => f.Code.Length > 0);
                    if (tagtofaceID != null)
                    {
                        query = query.Where(p => tagtofaceID.Contains(p.FaceID));
                    }

                    if (validTime > 0)
                    {
                        var startTime = DateTime.Now.AddSeconds(validTime * -1);
                        query = query.Where(s => s.CreateTime >= startTime);
                    }

                    query           = query.Where(p => faceIds.Contains(p.FaceID)).OrderBy(s => s.CreateTime);
                    page.TotalCount = query.Count();
                    query           = query.Skip(page.Offset).Take(page.Pagesize);

                    list = query.ToList();
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
            }
            return(list);
        }