带有WCF的EntityFramework 6.1.3。内存消耗w3wp.exe

时间:2016-05-19 08:43:13

标签: asp.net-mvc entity-framework wcf npgsql w3wp

 public IEnumerable<FormsDto> GetForms(int TId, int AId)
    {
        using (var context = new NewEntities())
        {
            try
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                var FormList = (from NAC in context.Candidates.AsNoTracking().Where(d => d.IsDeleted == false && d.StatusId == 1 && d.TId == TenantId && d.AId == AId)
                                           select new FormsDto
                                           {
                                               CandidateId = NAC.CandidateId,
                                               ApplicationUserId = NAC.ApplicationUserId ?? 0,
                                               ChildName = NAC.CandidateFirstName + " " + ((NAC.CandidateMiddleName == null) ? "" : NAC.CandidateMiddleName) + " " + NAC.CandidateLastName,
                                               TID = NAC.TId ?? 0,
                                               AID = NAC.AId ?? 0,
                                               Classid = NAC.ClassId ?? 0,
                                               FormNo = NAC.FormNo
                                           }).ToList();

                foreach (FormsDto item in FormList)
                {
                    int classid = context.Classes.AsNoTracking().Where(d => d.IsDeleted == false && d.ClassId == item.Classid).FirstOrDefault().ClassId ?? 0;
                    item.ClassName = context.Classes.AsNoTracking().Where(d => d.ClassID == classid && d.IsDeleted == false && d.TID == item.TID).FirstOrDefault().Displaylabel;

                }
                return FormList;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                context.Configuration.AutoDetectChangesEnabled = true;
            }
        }
    }
  

上面是我的WCF方法。当被调用(返回8/9记录)时,w3wp.exe消耗高达150MB的高内存。我只想知道我的方法是正确的,无论我在上面返回什么。

0 个答案:

没有答案