LINQ to Entities在按GUID搜索时返回NULL

时间:2013-08-01 11:49:38

标签: entity-framework-4 linq-to-entities

我有一个LINQ to Entities Query,假设根据提供的GUID返回特定的结果集。

    [OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
    public List<OrderDetails> GetOrderDetailsByGUID(Guid OrderID)
    {
        var listit =(from OV in EC.OrderProductVariants
                join O in EC.Orders on OV.OrderId equals O.Id
                join PV in EC.ProductVariants on OV.ProductVariantId equals PV.Id
                join P in EC.Products on PV.ProductId equals P.Id
                join CT in EC.Customers on O.CustomerId equals CT.Id
                join AD in EC.Addresses on CT.BillingAddress_Id equals AD.Id
                where O.OrderGuid == OrderID
                select new OrderDetails
                {
                    OrderID = O.OrderGuid,
                    Company = AD.Company,
                    ShippingMethod = O.ShippingMethod,
                    Product = P.Name,
                    QuantityOnOrder = OV.Quantity
                }
                    ).ToList();

        return listit;
    }

它返回NULL,有人能告诉我我做错了吗?

1 个答案:

答案 0 :(得分:2)

在这样的场景中可以使用的所有解决方案都是创建一个视图并只执行一个代码来访问它

var q = EC.OrderProductVariants.SingleOrDefault(u => u.OrderGuid.Equals(guid));