2

使用 Linq 对“键/值表”的实体执行以下查询时,我得到[System.NotSupportedException] "Specified method not supported"

有人可以提示我做错了什么吗?

var Pivot = context.goe_postmeta.GroupBy(pm => pm.post_id).Select(
                g => new PivotTemp
                    {
                        ID = g.Key, 
                        FirstName = g.FirstOrDefault(p => p.meta_key == "_billing_first_name").meta_value, 
                        LastName = g.FirstOrDefault(p => p.meta_key == "_billing_last_name").meta_value, 
                        Address = g.FirstOrDefault(p => p.meta_key == "_billing_address_1").meta_value, 
                        PostCode = g.FirstOrDefault(p => p.meta_key == "_billing_postcode").meta_value, 
                        Phone = g.FirstOrDefault(p => p.meta_key == "_billing_phone").meta_value, 
                        OrderTotal = g.FirstOrDefault(p => p.meta_key == "_order_total").meta_value, 
                        PickupLocation = g.FirstOrDefault(p => p.meta_key == "_pickup_location").meta_value, 
                        PickupTime = g.FirstOrDefault(p => p.meta_key == "_pickup_time").meta_value, 
                        OrderItems = g.FirstOrDefault(p => p.meta_key == "_order_items").meta_value
                    }).ToList();
4

1 回答 1

0
var Pivot = context.goe_postmeta.GroupBy(pm => pm.post_id).Select(
                g => new PivotTemp
                    {
                        ID = g.Key, 
                        FirstName = g.FirstOrDefault(p => p.meta_key == "_billing_first_name").meta_value, 
                        LastName = g.FirstOrDefault(p => p.meta_key == "_billing_last_name").meta_value, 
                        Address = g.FirstOrDefault(p => p.meta_key == "_billing_address_1").meta_value, 
                        PostCode = g.FirstOrDefault(p => p.meta_key == "_billing_postcode").meta_value, 
                        Phone = g.FirstOrDefault(p => p.meta_key == "_billing_phone").meta_value, 
                        OrderTotal = g.FirstOrDefault(p => p.meta_key == "_order_total").meta_value, 
                        PickupLocation = g.FirstOrDefault(p => p.meta_key == "_pickup_location").meta_value, 
                        PickupTime = g.FirstOrDefault(p => p.meta_key == "_pickup_time").meta_value, 
                        OrderItems = g.FirstOrDefault(p => p.meta_key == "_order_items").meta_value
                    }).ToList();

也许是因为你错过了“。” 在 ToList() 之前?只是一个猜测

于 2013-03-07T17:45:57.837 回答