我正在尝试LinqKit
AsExpandable
在我的EfCore2.0
项目中使用,但我遇到了这个Includes
不起作用的问题。
在尝试调试时,我LinqKit
从 github 下载了源代码,并将项目中的Nuget
引用替换为项目引用。
在调试LinqKit
项目时,我注意到我的调用Include
没有达到我设置的断点ExpandableQueryOfClass<T>.Include
。
我做了一些进一步的测试,并注意到如果我第一次转换到断点会被命中ExpandableQueryOfClass
(这是我公开的一个内部类LinqKit
,所以如果我引用Nuget
包,我就无法进行转换)。
这是一个错误LinqKit
还是我做错了什么?
这是我的测试代码。
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Internal.DAL.Db;
using Internal.Models.Customer;
using LinqKit; // Referencing LinqKit.Microsoft.EntityFrameworkCore
using Xunit;
namespace Internal.EntityFramework.Tests
{
public class UnitTest1
{
private DbContextOptionsBuilder<DataContext> _ctxBuilder =>
new DbContextOptionsBuilder<DataContext>().UseSqlServer(Connection.String);
[Fact]
public async Task SuccessTest()
{
using (var ctx = new DataContext(_ctxBuilder.Options))
{
var query =
(
// this cast is the only difference between the methods
(ExpandableQueryOfClass<Order>)
ctx.Orders
.AsExpandable()
)
.Include(r => r.Customer)
.Take(500);
var responses = await query.ToListAsync();
// this succeeds
Assert.All(responses, r => Assert.NotNull(r.Customer));
}
}
[Fact]
public async Task FailTest()
{
using (var ctx = new DataContext(_ctxBuilder.Options))
{
var query = ctx.Orders
.AsExpandable()
.Include(r => r.Customer)
.Take(500);
var responses = await query.ToListAsync();
// this fails
Assert.All(responses, r => Assert.NotNull(r.Customer));
}
}
}
}
编辑: LinqKit github 存储库上2018-05-15
有一个未解决的问题。