C#(model + linq):
public class RepairRecord
{
public Guid? CheckId {get;set;}
//more properties
}
public class ProductTracking
{
public Guid? CheckId {get;set;}
//more properties
}
var query = from a in context.Set<RepairRecord>()
join b in context.Set<ProductTracking>() on a.CheckId.Value equals b.CheckId.Value
select 1;
var queryResult = query.FirstOrDefault();
SQL:
SELECT
[Limit1].[C1] AS [C1]
FROM ( SELECT TOP (1)
1 AS [C1]
FROM [dbo].[MES_REPAIR_RECORD] AS [Extent1]
INNER JOIN [dbo].[MES_PRODUCT_TRACKING] AS [Extent2] ON ([Extent1].[CHECK_ID] = [Extent2].[CHECK_ID]) OR (([Extent1].[CHECK_ID] IS NULL) AND ([Extent2].[CHECK_ID] IS NULL))
) AS [Limit1]
我不需要空值匹配,如何修改我的C#以使sql看起来像这样:
SELECT
[Limit1].[C1] AS [C1]
FROM ( SELECT TOP (1)
1 AS [C1]
FROM [dbo].[MES_REPAIR_RECORD] AS [Extent1]
INNER JOIN [dbo].[MES_PRODUCT_TRACKING] AS [Extent2] ON ([Extent1].[CHECK_ID] = [Extent2].[CHECK_ID])
) AS [Limit1]
我的场景中模型的定义无法修改