好的,我正用这个把头撞到墙上;-)
给定我的数据库中名为 Address、Customer 和 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 列表,每条记录都有一个客户姓名和一个邮政编码,但客户类型字段始终为空。
我已经多次使用不同的数据库表和投影类重新创建了这个问题。
有人有什么想法吗?