Can you tell my why the first query works and the second one doesn't. The first query correctly issues two sql calls. The second issues a subselect.
LINQ Support Classes Lib - 2.6.8.1219
ORM Support Classes Lib - 2.6.8.1211
[TestMethod()]
public void TestBasicLinqQueryWithProjectionAndRelatedEntitiesWithProjection2()
{
var qry = (from l in context.CVE
select new
{
l.CVEId,
Comments = l.CVEComment.Select(a=> new { a.CVECommentId, a.CreatedOn })
});
var list = qry.ToList();
Assert.IsTrue(list != null);
}
SQL Issued :
exec sp_executesql N'SELECT [LPLA_1].[CVEId], [LPLA_1].[CVENumber], @LO11 AS [LPFA_2] FROM [VRRA].[Vulnerability].[CVE] [LPLA_1] ',N'@LO11 int',@LO11=1
SELECT [LPLA_2].[CVECommentId], [LPLA_2].[CreatedOn], [LPLA_2].[CVEId] FROM [VRRA].[Vulnerability].[CVEComment] [LPLA_2] WHERE ( ( ( EXISTS (SELECT [LPLA_1].[CVEId] FROM [VRRA].[Vulnerability].[CVE] [LPLA_1] WHERE ( [LPLA_1].[CVEId] = [LPLA_2].[CVEId])))))
This one throws an exception.
[TestMethod()]
public void TestBasicLinqQueryWithProjectionAndRelatedEntitiesWithProjection2()
{
var qry = (from l in context.CVE
select new
{
l.CVEId,
Comments = l.CVEComment.Select(a=> new { a.CVECommentId })
});
var list = qry.ToList();
Assert.IsTrue(list != null);
}
Test method VRRA.Tests.LLBLGenTests.TestBasicLinqQueryWithProjectionAndRelatedEntitiesWithProjection2 threw exception: System.Data.SqlClient.SqlException: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression..
SQL Issued :
SELECT [LPLA_1].[CVEId], [LPLA_1].[CVENumber], (SELECT [LPLA_2].[CVECommentId] FROM [VRRA].[Vulnerability].[CVEComment] [LPLA_2] WHERE ( ( [LPLA_1].[CVEId] = [LPLA_2].[CVEId]))) AS [LPFA_2] FROM [VRRA].[Vulnerability].[CVE] [LPLA_1]