Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: ef 6.1.1 problem while using WithRequiredPrincipal

$
0
0
There is a problem in ef 6.1.1 while using WithRequiredPrincipal, The example Code like this

public partial class MUser
{
public int ID { get; set; }
public string Name { get; set; }

public MUserInfo MUserInfo { get; set; }
}

public partial class MUserInfo
{
public int UserID { get; set; }
public Nullable<bool> IsActive { get; set; }

public MUser MUser { get; set; }
}

public class MUserMap : EntityTypeConfiguration<MUser>
{
public MUserMap()
{
this.HasKey(t => t.ID);
this.Property(t => t.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
this.Property(t => t.Name).HasMaxLength(100);
this.ToTable("MUser");
this.Property(t => t.ID).HasColumnName("ID");
this.Property(t => t.Name).HasColumnName("Name");

this.HasRequired(a => a.MUserInfo).WithRequiredPrincipal(t => t.MUser);
}
}

public class MUserInfoMap : EntityTypeConfiguration<MUserInfo>
{
public MUserInfoMap()
{
this.HasKey(t => t.UserID);
this.Property(t => t.UserID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
this.ToTable("MUserInfo");
this.Property(t => t.UserID).HasColumnName("UserID");
this.Property(t => t.IsActive).HasColumnName("IsActive");
}
}

The using Code is

context.MUserInfos.Include(t => t.MUser).ToList();

While using EF6.0 and EF6.1.0 ,then generate sql is:

SELECT
[Extent1].[UserID] AS [UserID],
[Extent1].[IsActive] AS [IsActive],
[Extent2].[ID] AS [ID],
[Extent2].[Name] AS [Name]
FROM [dbo].[MUserInfo] AS [Extent1]
INNER JOIN [dbo].[MUser] AS [Extent2] ON [Extent1].[UserID] = [Extent2].[ID]


While using EF6.1.1 ,then generate sql is:

SELECT
[Extent1].[UserID] AS [UserID],
[Extent1].[IsActive] AS [IsActive],
[Join1].[ID] AS [ID],
[Join1].[Name] AS [Name]
FROM [dbo].[MUserInfo] AS [Extent1]
LEFT OUTER JOIN (SELECT [Extent2].[ID] AS [ID], [Extent2].[Name] AS [Name], [Extent3].[UserID] AS [UserID]
FROM [dbo].[MUser] AS [Extent2]
LEFT OUTER JOIN [dbo].[MUserInfo] AS [Extent3] ON [Extent2].[ID] = [Extent3].[UserID] ) AS [Join1] ON [Extent1].[UserID] = [Join1].[UserID]

Is it a bug? Please check it, thanks.

Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>