var parentIfaces = new Guid[0];
var entityInterfaces = entity.Interfaces.Select(m => m.Linked);
var qwe = entityInterfaces.Where(m => !parentIfaces.Contains(m.Id))
qwe.Count() == 0 // This will always be 0
This code gets translated into:
SELECT [a].[#a.Id] ,
[a].[#a.TypeId] ,
[a].[#a.Description] ,
[a].[#a.Name] ,
[a].[#a.SysName] ,
[a].[#a.Version] ,
[a].[#a.Revision]
FROM ( SELECT [b].[Id] ,
112 AS [TypeId] ,
[b].[Linked_Id] ,
[b].[Owner_Id]
FROM [dbo].[DocEntity_MlInterfaces] [b]
WHERE ( [b].[Owner_Id] = @p0_0 )
) [c]
INNER JOIN ( SELECT [d].[Id] AS [#a.Id] ,
139 AS [#a.TypeId] ,
[d].[Description] AS [#a.Description] ,
[d].[Name] AS [#a.Name] ,
[d].[SysName] AS [#a.SysName] ,
[d].[Version] AS [#a.Version] ,
[d].[Revision] AS [#a.Revision]
FROM [dbo].[EntityInterface] [d]
) [a] ON ( [c].[Linked_Id] = [a].[#a.Id] )
WHERE ( NOT [a].[#a.Id] IN ( NULL ) ) ;
So the last WHERE is always evaluated into FALSE
UPD:
As for now, I fixed the problem with this
var parentIfaces = new Guid[0].AsQueryable();
So, this gets translated into the proper query
SELECT [a].[#a.Id] ,
[a].[#a.TypeId] ,
[a].[#a.Description] ,
[a].[#a.Name] ,
[a].[#a.SysName] ,
[a].[#a.Version] ,
[a].[#a.Revision]
FROM ( SELECT [b].[Id] ,
112 AS [TypeId] ,
[b].[Linked_Id] ,
[b].[Owner_Id]
FROM [dbo].[DocEntity_MlInterfaces] [b]
WHERE ( [b].[Owner_Id] = @p0_0 )
) [c]
INNER JOIN ( SELECT [d].[Id] AS [#a.Id] ,
139 AS [#a.TypeId] ,
[d].[Description] AS [#a.Description] ,
[d].[Name] AS [#a.Name] ,
[d].[SysName] AS [#a.SysName] ,
[d].[Version] AS [#a.Version] ,
[d].[Revision] AS [#a.Revision]
FROM [dbo].[EntityInterface] [d]
) [a] ON ( [c].[Linked_Id] = [a].[#a.Id] )
WHERE ( NOT EXISTS ( SELECT *
FROM [dbo].[DocEntity_MlInterfaces] [e]
WHERE ( ( [e].[Owner_Id] = @p0_1 )
AND ( [e].[Linked_Id] = [a].[#a.Id] )
) )
) ;
UPDATE:
More problems with this situation:
using (var tr = s.OpenTransaction())
{
var ssss = (from r in Session.Current.Query.All<RegDeletedItem>()
where r.DeletedItem.In(new List<GeneralLink>())
select r).ToList();
tr.Complete();
}
This code generates invalid SQL, so SQL server cannot execute the query at all. I've sent you email with tests.
new Guid[0]
is translated toNULL
in SQL?Btw, what is
new Guid[0]
? C# shouldn't handle this...yes
BTW, see UPD
Ah, sorry ;) By some reason I decided you used square brackets instead of regular ones.