这是一个代码示例:
MyDataContext context = new MyDataContext();
Symbol symbol = (from s in context.Symbols where s.ID = 3257 select s).First();
ProtocolVariable[] variables = symbol.ProtocolVariables.ToArray();
context.Dispose();
使用调试器我看到变量的数量等于3(variables.Length == 3)。 现在我改变了一点代码:
MyDataContext context = new MyDataContext();
DataLoadOptions dlo = new dataLoadOptions();
dlo.LoadWith<Symbol>(s => s.ProtocolVariables);
context.LoadOptions = dlo;
Symbol symbol = (from s in context.Symbols where s.ID = 3257 select s).First();
ProtocolVariable[] variables = symbol.ProtocolVariables.ToArray();
Context.Dispose();
调试器现在向我显示变量数等于1。
这怎么可能?
以下是一些补充信息(我不知道它是否重要):
这是第一个代码示例背后的SQL查询:
SELECT
[t0].[ID],
[t0].[SubsystemID],
[t0].[GenericName],
[t0].[LocalName],
[t0].[TypeID],
[t0].[Array],
[t0].[Array2],
[t0].[UnitID],
[t0].[Description],
[t0].[ProtocolID]
FROM [dbo].[Symbols] AS [t0]
WHERE [t0].[ID] = 3257
这是第二个代码示例背后的SQL查询:
SELECT
[t0].[ID],
[t0].[SubsystemID],
[t0].[GenericName],
[t0].[LocalName],
[t0].[TypeID],
[t0].[Array],
[t0].[Array2],
[t0].[UnitID],
[t0].[Description],
[t0].[ProtocolID],
[t1].[ID] AS [ID2],
[t1].[SymbolID],
[t1].[SubsystemID] AS [SubsystemID2],
[t1].[GenericName] AS [GenericName2],
[t1].[LocalName] AS [LocalName2],
[t1].[TypeID] AS [TypeID2],
[t1].[Array] AS [Array3],
[t1].[Array2] AS [Array22],
[t1].[UnitID] AS [UnitID2],
[t1].[Description] AS [Description2],
[t1].[ProtocolID] AS [ProtocolID2],
[t1].[VariableTypeID],
(
SELECT COUNT(*)
FROM [dbo].[ProtocolVariables] AS [t2]
WHERE [t2].[SymbolID] = [t0].[ID]
) AS [value]
FROM [dbo].[Symbols] AS [t0]
LEFT OUTER JOIN [dbo].[ProtocolVariables] AS [t1] ON [t1].[SymbolID] = [t0].[ID]
WHERE [t0].[ID] = 3257
ORDER BY [t0].[ID], [t1].[ID]
答案 0 :(得分:0)
我设法解决了这个问题:&#34; ProtocolVariables&#34;中的ID字段视图必须是唯一的。
我无法巧妙地解释它。我只能描述它 - 我希望它会为你节省一些时间。
没有最后一步(NEWID功能)我观察到了我在问题中描述的行为。