我有以下EF代码优先模型
public class A
{
public int Id { get; set; }
public B B { get; set; }
}
public class B
{
public int Id { get; set; }
public string Text { get; set; }
}
这些映射
modelBuilder.Entity<A>()
.HasOptional(a => a.B)
.WithMany();
modelBuilder.Entity<B>()
.HasKey(b => b.Id);
当我运行此查询时:
context.As.Include(a => a.B).FirstOrDefault();
导致以下sql:
SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent2].[Id] AS [Id1],
[Extent2].[Text] AS [Text]
FROM [dbo].[A] AS [Extent1]
LEFT OUTER JOIN [dbo].[B] AS [Extent2] ON [Extent1].[B_Id] = [Extent2].[Id]
我期待得到INNER JOIN而不是LEFT OUTER JOIN
答案 0 :(得分:3)