申请版本:
Asp Net Core 1.1
EF:Microsoft.EntityFrameworkCore(1.1.1)
行:
_dbContext.MyTable1.Include(c => c.MyIntermediateTable).ThenInclude(k => k.Select(x => x.MyTable2))。ToList();
例外:
属性表达式' k => {来自MyIntermediateTable x in k select [X] .MyTable2}'无效。表达式应代表a 财产访问:' t => t.MyProperty&#39 ;.有关的更多信息 包括相关数据
我的实体
[Table("MyTable1")]
public class MyTable1
{
public MyTable1()
{
MyIntermediateTable = new List<MyIntermediateTable>();
}
[Column("MyPK1")]
public int MyPK1 { get; set; }
public string Name{ get; set; }
public virtual List<MyIntermediateTable> MyIntermediateTable{ get; set; }
}
[Table("MyIntermediateTable")]
public class MyIntermediateTable
{
public int MyPK1 { get; set; }
public int MyPK2 { get; set; }
public virtual MyTable1 MyTable1 { get; set; }
public virtual MyTable2 MyTable2 { get; set; }
}
[Table("MyTable2")]
public class MyTable2
{
public MyTable2()
{
MyIntermediateTable = new List<MyIntermediateTable>();
}
[Column("MyPK2")]
public int MyPK2 { get; set; }
public string Name{ get; set; }
public virtual List<MyIntermediateTable> MyIntermediateTable{ get; set; }
}
模型构建器(Fluent API)
modelBuilder.Entity<MyIntermediateTable>((item) =>
{
item.HasKey(p => new { p.MyPK1, p.MyPK2 });
item.HasOne(u => u.MyTable1).WithMany(u => u.MyIntermediateTable).HasForeignKey(u => u.MyPK1);
item.HasOne(u => u.MyTable2).WithMany(u => u.MyIntermediateTable).HasForeignKey(u => u.MyPK2);
});
modelBuilder.Entity<MyTable1>((item) =>
{
item.HasKey(p => p.MyPK1);
item.HasMany(u => u.MyIntermediateTable).WithOne(u => u.MyTable1).HasForeignKey(u => u.MyPK1);
});
modelBuilder.Entity<MyTable2>((item) =>
{
item.HasKey(p => p.MyPK2);
item.HasMany(u => u.MyIntermediateTable).WithOne(u => u.MyTable2).HasForeignKey(u => u.MyPK2);
});
答案 0 :(得分:5)
Visual Studio中的Intellisense只会在进行自动竞争时显示列表属性。
这是一个错误(或智能感知在编写时无法处理的事情),当有两个与签名匹配的重载时会发生错误:一个用于T
其他用于{{ 1}}。
出现这种情况时,即使智能感知器不会显示IEnumerable<T>
,也只需键入.ThenInclude(m => m.MyProperty)
,忽略IDE显示的任何错误。
关闭方法括号后,错误将消失。
此漏洞由dotnet roslyn GitHub存储库中的GitHub问题Completion missing members of lambda parameter in fault tolerance case跟踪。