0

我有以下存储库方法:-

public RackJoin AllFindRackDetails_J(int id)
        {
            var tmsRack = tms.TMSRacks
            .Include(a=>a.Zone)
            .Include(a2=>a2.DataCenter)
            .Include(a3=>a3.Technology)
            .SingleOrDefault(a3=>a3.TMSRackID == id);

         var IT360Rack = entities.Resources
             .Include(a => a.ComponentDefinition)
             .Include(a=>a.ResourceLocation.SiteDefinition.SDOrganization)
             .Include(a=>a.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization)
           //  .Include(a=>a.CI)
             .SingleOrDefault(a2=>a2.RESOURCEID == tmsRack.Technology.IT360ID);
         RackJoin rj = new RackJoin { 

            Rack = tmsRack,
            Resource = IT360Rack,
            Technology = tmsRack.Technology,
            ComponentDefinition = IT360Rack.ComponentDefinition,
            Site = IT360Rack.ResourceLocation.SiteDefinition.SDOrganization,
            Customer = IT360Rack.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization

        };
         return rj;
        }

从以下操作方法调用:-

public ActionResult Details(int id,string detailName=null)
        {
            var racks = repository.AllFindRackDetails_J(id);


            return View(racks);
        }

我知道,如果存储库方法返回 IQurable<>,那么一旦我遍历 Iqurable 或调用 .list(),数据库就会被命中。但是如果存储库方法只能返回单个对象,当实际的数据库交互发生时会发生什么呢?

4

1 回答 1

3

SingleOrDefault导致查询立即执行。对于所有IQueryable<T>返回IQueryable<T>. 例如First,CountMaxall 立即执行。

于 2013-08-15T08:56:47.193 回答