亚音速3 LINQ的投影问题 [英] Subsonic 3 Linq Projection Issue
问题描述
OK,我敲我的头靠在墙上这一个; - )
OK I'm banging my head against a wall with this one ;-)
由于表被叫地址,客户和CustomerType,我要显示有关客户合并汇总信息,所以我创建一个查询,加入这两个表并检索特定结果。
Given tables in my database called Address, Customer and CustomerType, I want to display combined summary information about the customer so I create a query to join these two tables and retrieve a specified result.
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
CustomerSummaryView is a simple POCO
public class CustomerSummaryView
{
public string Postcode { get; set; }
public string CustomerType { get; set; }
public string CustomerName { get; set; }
}
现在出于某种原因,这并不工作,我得到了CustomerSummaryView结果一个IEnumerable列表,每条记录都有一个客户名和后code,但客户类型字段始终为空。
Now for some reason, this doesn't work, I get an IEnumerable list of CustomerSummaryView results, each record has a customer name and a postcode but the customer type field is always null.
我已经重新创建这个问题多次与不同的数据库表,和预期类。
I've recreated this problem several times with different database tables, and projected classes.
任何人任何想法?
推荐答案
我不能瑞普这个问题 - 这是一个测试我只是想:
I can't repro this issue - here's a test I just tried:
[Fact]
public void Joined_Projection_Should_Return_All_Values() {
var qry = (from c in _db.Customers
join order in _db.Orders on c.CustomerID equals order.CustomerID
join details in _db.OrderDetails on order.OrderID equals details.OrderID
join products in _db.Products on details.ProductID equals products.ProductID
select new CustomerSummaryView
{
CustomerID = c.CustomerID,
OrderID = order.OrderID,
ProductName = products.ProductName
});
Assert.True(qry.Count() > 0);
foreach (var view in qry) {
Assert.False(String.IsNullOrEmpty(view.ProductName));
Assert.True(view.OrderID > 0);
Assert.False(String.IsNullOrEmpty(view.CustomerID));
}
}
这传递完美。我想知道,如果你使用的保留字呢?
This passed perfectly. I'm wondering if you're using a reserved word in there?
这篇关于亚音速3 LINQ的投影问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!