次の 2 つのモデルがあります。関係が 1 対 1 である 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 に関するすべてのデータが一度に取得されます (イーガー ロード)。だから私は次の2つの質問があります:-
私の場合、データはデータベースへの 1 回のクエリで取得されます (Eager Loading)。
SQL Server 2008 r2 を使用しています。では、データベース クエリをチェックして、実際にデータベースにヒットしたクエリの数を確認する方法を教えてください。