Entity framework 4 按GUID搜索时返回NULL的LINQ到实体

Entity framework 4 按GUID搜索时返回NULL的LINQ到实体,entity-framework-4,linq-to-entities,Entity Framework 4,Linq To Entities,我有一个LINQ to Entities查询,它假定根据提供的GUID返回特定的结果集 [OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)] public List<OrderDetails> GetOrderDetailsByGUID(Guid OrderID) { var listit =(from OV in EC.OrderProductVariants

我有一个LINQ to Entities查询,它假定根据提供的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;
    }
[OperationContract,WebGet(ResponseFormat=WebMessageFormat.Json)]
公共列表GetOrderDetailsByGUID(Guid OrderID)
{
var listit=(来自EC.OrderProductVariants中的OV)
在OV.OrderId等于O.Id的EC.Orders中加入O
将PV加入到OV.ProductVariantId等于PV.Id的EC.ProductVariants中
在PV.ProductId等于P.Id的EC产品中加入P
在O.CustomerId等于CT.Id的情况下将CT加入EC.Customers
将AD加入CT.BillingAddress_Id等于AD.Id上的EC.地址
其中O.OrderGuid==OrderID
选择新订单详细信息
{
OrderID=O.OrderGuid,
公司,
ShippingMethod=O.ShippingMethod,
产品=零件名称,
QuantityOnOrder=OV.数量
}
).ToList();
返回listit;
}

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

在这种情况下,所有可行的解决方案都是创建一个视图,只需执行一行代码即可访问它

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

什么确切地返回为NULL?整个语句。我检查了SQL数据库中是否存在任何给定GUID的有效记录。老实说,如果
ToList()
可以返回
null
,我很惊讶,因为它没有文档记录到。你的意思是它返回一个空的
列表
?是的,我自己也很难堪。。在Chrome、Firefox中检查了我的控制台,并在方法中添加了断点。没有错误。运行Fiddler时,查询没有超时或类似的任何有趣的事情,这可能是筛选出来的连接之一。尝试删除所有联接,然后逐个将它们添加回。