2013-07-11 4 views
22

Ich habe folgende Repository-Methode: -Der Include Pfadausdruck auf eine Navigationseigenschaft definiert nach Art beziehen, müssen

public AccountDefinition GetCustomer2(int id) 
{ 
    var c = entities.AccountDefinitions 
      .Where(p=>p.ORG_ID==id) 
      .Include(a => a.SDOrganization) 
      .Include(a2 => a2.SiteDefinitions) 
      .Include(a3 => a3.SDOrganization.AaaPostalAddresses) 
      .Include(a4 => a4.SiteDefinitions.SelectMany 
           (a5 => a5.DepartmentDefinitions.SelectMany 
            (a6 => a6.SDUsers.Select 
              (a7 => a7.AaaUser)))) 
                .SingleOrDefault(); 

    return c; 
} 

Die folgende Aktion-Methode, die die obige Methode aufruft: -

public ActionResult Details2(int id = 0) 
{ 
    AccountDefinition cd = repository.GetCustomer2(id); 
    return View("copy",cd); 
} 

, aber wenn ich auf die Aktion Methode navigieren, bekomme ich folgende Fehler auf der Repository-Klasse: -

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.

Was ist falsch an meinem Code?

Antwort

29

Ich denke, man kann so etwas wie

public AccountDefinition GetCustomer2(int id) 
     { 

      var c = entities.AccountDefinitions.Where(p=>p.ORG_ID==id) 
       .Include(a => a.SDOrganization) 
       .Include(a2 => a2.SiteDefinitions) 
       .Include(a3 => a3.SDOrganization.AaaPostalAddresses) 
       .Include(a4 => a4.SiteDefinitions.Select(a5 => a5.DepartmentDefinitions.Select(a6 => a6.SDUsers.Select(a7 => a7.AaaUser)))); 

      return c; 
     } 
+0

danke für die Antwort tun wollen, aber die SDOrganization keinen .Select. Und wenn ich Ihren Code schreibe, erhalte ich den folgenden Fehler: - "" Fehler 'TMS.Models.SDOrganization' enthält keine Definition für 'Select' und keine Erweiterungsmethode 'Select' akzeptiert ein erstes Argument vom Typ ' TMS.Models.SDOrganization 'könnte gefunden werden (fehlt dir eine using-Direktive oder eine Assembly-Referenz? "" –

+7

Ich sehe, dann ist das Problem wahrscheinlich SelectMany, ändere SelectMany stattdessen auf Select. –

+1

Ich steckte an einem anderen Problem, aber du bist dran Antwort zeigte mir in die richtige Richtung –

Verwandte Themen