Subsonic Issue 3 Linq Projection

Ok i'm banging my head against the wall with this ,-)

The Address, Customer, and CustomerType tables listed in my database, I want to display general summary information about the client, so I create a query to combine these two tables and get the 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 is a Simple POCO

public class CustomerSummaryView
{
    public string Postcode { get; set; }
    public string CustomerType { get; set; }
    public string CustomerName { get; set; }
}

Now for some reason this does not work, I get a list of CustomerSummaryView results in IEnumerable, each record has a customer name and zip code, but the client type field is always null.

I recreated this problem several times with different database tables and projected classes.

Any ideas?

+1
source share
4 answers

- , :

[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));
    }

}

. , ?

+2

, , Rob, , , John CustomerType type.Description.

, - Projection Mapper , . , , .

, Subsonic.Core.dll, .

, , .

0

31.03.2010, 2 , . .

:

        var data =
            (from m in Metric.All()
             where m.ParentMetricId == parentId
             select new
                    {
                         m.MetricName,
                         m.MetricId,
                    })
                    .ToList();

        var treeData =
            from d in data
            select new TreeViewItem
                    {
                        Text = d.MetricName,
                        Value = d.MetricId.ToString(),
                        LoadOnDemand = true,
                        Enabled = true,
                    };

        return new JsonResult { Data = treeData };

Subsonic, , . .

0

All Articles