Subsonic 3 Linq Projection Issue

 ̄綄美尐妖づ 提交于 2019-12-02 03:32:37

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?

Yes, the reason Rob's example works is because his projection's property names match exactly, whereas John's original example has a difference between CustomerType and type.Description.

This shouldn't have been a problem, but it was - the Projection Mapper was looking for properties of the same name and wasn't mapping a value if it didn't find a match. Therefore, your projection objects' properties would be default values for its type if there wasn't an exact name match.

The good news is, I got the latest source today and built a new Subsonic.Core.dll and the behavior is now fixed.

So John's code above should work as expected.

I just downloaded the latest build from 3/21/2010, which is about 2 months after the last poster on this thread, and the problem still exists in the packaged binary. Bummer.

Here what I have to do:

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

If I try to do the projection directly from the Subsonic query, the Text property ends up with the ID, and the Value property ends up with the Name. Very strange.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!