我有以下两种型号;AccountDefinition & SDOrganization 的关系是一对一的。
public partial class AccountDefinition
{
public AccountDefinition()
{
this.AccountSiteMappings = new HashSet<AccountSiteMapping>();
}
public long ORG_ID { get; set; }
public virtual SDOrganization SDOrganization { get; set; }
public virtual ICollection<AccountSiteMapping> AccountSiteMappings { get; set; }}
&
public partial class SDOrganization
{
public SDOrganization()
{
this.AccountAttachments = new HashSet<AccountAttachment>();
this.SDOrgUsers = new HashSet<SDOrgUser>();
this.AaaContactInfoes = new HashSet<AaaContactInfo>();
this.AaaUsers = new HashSet<AaaUser>();
this.AaaPostalAddresses = new HashSet<AaaPostalAddress>();
}
public long ORG_ID { get; set; }
public string NAME { get; set; }
public virtual AccountDefinition AccountDefinition { get; set; }
public virtual SDOrgDetail SDOrgDetail { get; set; }
public virtual SDOrgStatu SDOrgStatu { get; set; }
public virtual ICollection<SDOrgUser> SDOrgUsers { get; set; }
public virtual ICollection<AaaContactInfo> AaaContactInfoes { get; set; }
public virtual ICollection<AaaUser> AaaUsers { get; set; }
public virtual ICollection<AaaPostalAddress> AaaPostalAddresses { get; set; }
}
在 Action 方法上,我对存储库进行了以下调用:-
public ActionResult Index(string searchTerm=null)
{
var accountdefinition = repository.FindAccountDefinition(searchTerm).ToList();
if (Request.IsAjaxRequest())
{
ViewBag.FromSearch = true;
return PartialView("_CustomerTable",accountdefinition);
}
return View(accountdefinition);
}
该方法的存储库如下所示:-
public IQueryable<AccountDefinition> FindAccountDefinition(string q)
{
return from ad in entities.AccountDefinitions.Include(a => a.SDOrganization)
where (q == null || ad.ORG_NAME.ToUpper().StartsWith(q.ToUpper()) )
select ad;
}
最后在视图上我得到了以下代码(仅部分代码):-
@model IEnumerable<TMS.Models.AccountDefinition>
//code goes here
<th>
@Html.DisplayNameFor(model => model.SUPPORT_EMAIL)
</th>
<th>
@Html.DisplayNameFor(model => model.Single().SDOrganization.DESCRIPTION)
</th>
<th></th>
</tr>
//code goes here
@foreach (var item in Model)
{
<td class="center">
@Html.DisplayFor(modelItem => item.SDOrganization.DESCRIPTION)
</td>
我假设因为在存储库方法中我添加了 .include 从广告返回
entities.AccountDefinitions.Include(a => a.SDOrganization)
因此,将立即检索有关 accountdefinition 和 SDorganization 的所有数据(急切加载)。所以我有以下两个问题:-
在我的情况下,将通过对数据库的单个查询检索到的数据(急切加载)。
我正在使用 SQL Server 2008 r2。那么我如何检查数据库查询以检查有多少查询实际命中数据库。