엔티티 프레임 워크 (필자는 6.0을 사용하고 있지만 업데이트가 필요할 경우)의 새로운 기능인 엔티티를 linq 쿼리에 바인딩하는 방법을 찾고 있습니다. 예를 들어 내가 가진 : 둘은 데이터베이스의 테이블에 매핑되는엔티티 프레임 워크에서 linq 쿼리
public class User
{
public string Name {get;set;}
public WorkPlace Place {get;set;}
public bool IsAlive{get;set;}
}
public class WorkPlace
{
public string Name {get;set;}
public bool IsActive {get;set;}
public Collection<User> Users;
}
을하고 내가 가지고있는 OnModelCreating
:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().ToTable(tableName: "users");
modelBuilder.Entity<WorkPlace>().ToTable(tableName: "workplaces");
}
하지만 (탐색 및 지연로드와) 다른 개체를 사용해야합니다 : 내가 사용자의 회사를 얻을 때
public class CustomUser
{
public string Name {get;set;}
public CustomWorkPlace Place {get;set;}
}
public class CustomWorkPlace
{
public string Name {get;set;}
public Collection<CustomUser> Users;
}
someBuilder.Entity<CustomUser>().ToLinq(cntx => cntx.Set<User>().Where(user => user.IsAlive)).MapProperties();
// the way of mapping properties is not important
someBuilder.Entity<CustomWorkPlace>().ToLinq(cntx => cntx.Set<WorkPlace>().Where(place => plase.IsActive)).MapProperties()
그리고 가장 흥미로운 것은 탐색을 통해 가고, 나는 활성화되지 않은 회사 및 COM에 대해 동일한을 얻을합니다 pany - 살아 있지 않은 User에 매핑 된 CustomUser
을 가져 오지 않아야합니다.
감사 등
무엇이 문제입니까? – Kinetic
엔티티 프레임 워크 또는 너겟 확장을 통해이 논리 (컨텍스트에서 내 사용자 정의 객체 가져 오기)를 어떻게 구현할 수 있습니까? – VVildVVolf
일반 엔티티를 사용하여 데이터를로드하고 거기에서 사용자 정의 데이터를 생성하십시오. – Kinetic