我有一些查询可以从这样的数据库中获取公司:
var fullTextSearchVal = "test";
var sql = $"SELECT * FROM Companies WHERE CONTAINS(*, '\"*{fullTextSearchVal}*\"')";
var result = _context.Companies.Include(i => i.Address).FromSql(sql).ToList();
它运行良好,但在运行Sql Server Profiler和检查选择器后有一点问题。它看起来像这样:
SELECT [i].[Id], [i].[AddressId], [i].[Email], [i].[Name], [i].[PhoneNumber], [i.Address].[Id], [i.Address].[Address], [i.Address].[City], [i.Address].[Country], [i.Address].[ZipCode]
FROM (
SELECT * FROM Companies WHERE CONTAINS(*, '"*test*"')
) AS [i]
LEFT JOIN [Address] AS [i.Address] ON [i].[AddressId] = [i.Address].[Id]
问题在于选择器。我可以使用Include和FromSql扩展(没有子SELECT)获得如下的查询吗?
SELECT [i].[Id], [i].[AddressId], [i].[Email], [i].[Name], [i].[PhoneNumber], [i.Address].[Id], [i.Address].[Address], [i.Address].[City], [i.Address].[Country], [i.Address].[ZipCode]
FROM [Companies] AS [i]
LEFT JOIN [Address] AS [i.Address] ON [i].[AddressId] = [i.Address].[Id]
WHERE CONTAINS([i].*, '"*test*"')