1

Telerik OpenAccess ORM을 처음 사용하고 데이터베이스 접근 방식을 사용하는 MVC 프로젝트에 처음 사용했습니다. 나는 내가 모달에서 도메인 클래스 & 쿼리 데이터베이스를 확장 할 수있는 방법을 알고 궁금 http://tv.telerik.com/watch/orm/building-a-mvc-3-application-database-first-with-openaccess-creating-model?seriesID=1529Telerik Openaccess ORM 도메인 모델 확장

: 나는 모델에 대한 자신의 사이트에이 튜토리얼 비디오를했다? 예를 들어, 나는 다음과 같은 클래스를 확장하고있어 생성 된 "사람"클래스 & 있습니다

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace MVCApplication 
{ 
    public partial class Person 
    { 
     public string PersonName 
     { 
      get 
      { 
       return this.FirstName + " " + this.LastName; 
      } 
     } 
    } 
} 

이 위 영상의 예와 매우 유사합니다. Person 테이블이나 특정 기준이 충족되는 Person 개체의 컬렉션에서 모든 레코드를 검색 할 수 있는지 궁금합니다. 내 "반환"쿼리는 어떻게됩니까? 나는

public List<Person> GetAllPeople() 
{ 
// return List here 
} 

public List<Person> GetAllPeopleFromLocationA(int locationID) 
{ 
//return List here 
} 

답변

2

는 일반적으로 도메인 클래스는 데이터베이스를 조회하는 것은 아니다 :(이 확장 된 모델 클래스에서 사용할 수 dbContext이 없어 난 당신이 부분에 GetAllPeopleGetAllPeopleFromLocationA 메소드를 추가하는 것이 좋습니다 도메인 컨텍스트의 클래스 다음과 같은 :

using (YourContextName context = new YourContextName()) 
{ 
    foreach (Person person in context.GetAllPeople()) 
    { 
     // you could access your custom person.PersonName property here 
    } 

    foreach (Person person in context.GetAllPeopleFromLocationA(someLocationID)) 
    { 
     // you could access your custom person.PersonName property here 
    } 
} 
:

public List<Person> GetAllPeople() 
{ 
    return this.People.ToList(); 
} 

public List<Person> GetAllPeopleFromLocationA(int locationID) 
{ 
    return this.People.Where(p => p.LocationID == locationID).ToList(); 
} 

다음과 같은 이러한 방법을 사용할 수 있습니다

관련 문제