LINQ查询不返回预期结果

时间:2017-07-26 11:00:23

标签: c# .net entity-framework linq

我有以下表格

CREATE TABLE [dbo].[Operation](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](50) NOT NULL,
    [TemplateFId] [int] NOT NULL,
    [ServerId] [int] NOT NULL,
 CONSTRAINT [PK_Operation] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[Template](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](50) NULL,
 CONSTRAINT [PK_Template] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

我需要获取与serverid匹配的所有模板以及操作表(TemplateFId)中不存在的模板。我正在使用:

var result = from template in context.Template
             join operation in context.Operation on template.Id equals operation.TemplateFId
             where operation.ServerId == serverId
             select template

我只得到他们的服务器ID匹配的那些。打破我的头脑,了解我怎么能这样做,但不能。

0 个答案:

没有答案