내가 함께 벽에 머리를 두드리는있어 확인이 하나 ;-)음속 3 Linq에 투사 문제
주소, 고객 및 CustomerType라는 내 데이터베이스에감안할 때 테이블, 나는 고객에 대한 통합 요약 정보를 표시 할 그래서이 두 테이블을 조인하고 지정된 결과를 검색하는 쿼리를 작성합니다.
var customers = (from c in tblCustomer.All()
join address in tblAddress.All() on c.Address equals address.AddressId
join type in tblCustomerType.All() on c.CustomerType equals type.CustomerTypeId
select new CustomerSummaryView
{
CustomerName = c.CustomerName,
CustomerType = type.Description,
Postcode = address.Postcode
});
return View(customers);
CustomerSummaryView 간단한 POCO 어떤 이유로 지금
public class CustomerSummaryView
{
public string Postcode { get; set; }
public string CustomerType { get; set; }
public string CustomerName { get; set; }
}
, 이것이 내가 CustomerSummaryView 결과를 IEnumerable 목록을 작동하지 않습니다이며, 각 레코드는 고객 이름과 우편 번호 만있다 고객 유형 필드는 항상 null입니다.
다른 데이터베이스 테이블과 예상되는 클래스를 사용하여이 문제를 여러 번 재현했습니다.
누구나 아이디어가 있으십니까?
안녕하세요 롭, 매핑이 정확하게 일치하므로 테스트가 통과했다고 생각합니다. Jon은 CustomerType = type.Description을 처리하고 있으며,이 문제 만이 문제가있는 유일한 속성입니다. 나는 매우 비슷한 무언가를 만났습니다. http://stackoverflow.com/questions/1734146/subsonic-3-linq-projecting-anonymous-types-but-not-class-types –