0

我有两个类似的查询,第一个:

var activatedSerialNumbers = (from activation in entities.Activations
                              where !canceledActivationsIds.Contains(activation.Id)
                              where activation.CustomerId == customerId
                              join licenseConfiguration in entities.LicenseConfigurations
                                              on activation.Id equals licenseConfiguration.ActivationId
                              where licenseConfiguration.ProductId == productId
                              join activatedSerialNumber in entities.ActivatedSerialNumbers
                                              on activation.Id equals activatedSerialNumber.ActivationId
                             where deactivatedSams.All(dsn => dsn.ToLower() != 
                                              activatedSerialNumber.Name.ToLower())
                             select new SamWithLicense
                             {
                                     Name = activatedSerialNumber.Name,
                                     Features = licenseConfiguration.LicenseFeatures
                             }).ToList();

第二:

var activationsForSam = (from activation in entities.Activations
                        where !canceledActivationsIds.Contains(activation.Id)
                        where activation.CustomerId == customerId
                        let activatedSerialNumbers = activation.ActivatedSerialNumbers
                                                    .Select(sn => sn.Name.ToLower())
                        where activatedSerialNumbers.Contains(loweredSn)
                        join licenseConfiguration in entities.LicenseConfigurations
                                             on activation.Id equals activatedProduct.ActivationId
                        select new SamWithLicense
                        {
                                   Name = selectedSerialNumber,
                                   Features = licenseConfiguration.LicenseFeatures
                        }).ToList();

在某些情况下,我一个接一个地执行它们,在大多数情况下它工作正常,但有时 - 不是。在第二个查询的结果中Counter从另一行获取:

Visual Studio - 快速观看 在此处输入图像描述

SQL 管理工作室 在此处输入图像描述

我想这是一个 EF 缓存或 smth 的问题,但不知道如何正确修复它。

4

1 回答 1

0

在您的第一个查询中,您将激活 Id (PK) 加入 LicenseConfigurations ActivationId (FK)

join licenseConfiguration in entities.LicenseConfigurations
on activation.Id equals licenseConfiguration.ActivationId

在您的第二个查询中,您似乎正在加入查询“activatedProduct”之外定义的值

join licenseConfiguration in entities.LicenseConfigurations
on activation.Id equals activatedProduct.ActivationId
于 2013-08-08T17:43:47.203 回答