fissoft / Fissoft.EntityFramework.Fts

Full Text Search for Microsoft SQL Server with Entity Framework
MIT License
59 stars 14 forks source link

FTS was not replaced on... #15

Closed Martin-DC closed 7 years ago

Martin-DC commented 7 years ago

Hi when I do single column search it works fine, but when I do multiple search search coding like: using (var container = new ProductSystemContainer(1)) { var text = FullTextSearchModelUtil.Contains("三星 iphone5",true); var q = container.Sku.Where(c => (c.Title+c.Keywords).Contains(text)); container.Database.Log = Console.WriteLine; var a = q.ToList(); Assert.IsTrue(a.Count>1); } it shows error

测试方法 ProductTest.SqlServerFullTextTest.FullTextTest 引发了异常: System.Data.Entity.Core.EntityCommandExecutionException: 执行命令定义时出错。有关详细信息,请参阅内部异常。 ---> System.Exception: FTS was not replaced on: SELECT [Extent1].[Id] AS [Id],
[Extent1].[Title] AS [Title], [Extent1].[Keywords] AS [Keywords], [Extent1].[Description] AS [Description],
[Extent1].[Created] AS [Created], [Extent1].[LastModified] AS [LastModified] FROM [dbo].[Sku] AS [Extent1] WHERE [Extent1].[Title] + CASE WHEN ([Extent1].[Keywords] IS NULL) THEN N'' ELSE [Extent1].[Keywords] END LIKE @plinq0 ESCAPE N'~' 在 Fissoft.EntityFramework.Fts.FtsInterceptor.ReplacePropertyWithParameterKeyword(FtsSetting setting, String flag, String text, DbCommand cmd) 在 Fissoft.EntityFramework.Fts.FtsInterceptor.ReplaceProperty(DbCommand cmd, String flag) 在 Fissoft.EntityFramework.Fts.FtsInterceptor.RewriteFullTextQuery(DbCommand cmd) 在 Fissoft.EntityFramework.Fts.FtsInterceptor.ReaderExecuting(DbCommand command, DbCommandInterceptionContext1 interceptionContext) 在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__d(IDbCommandInterceptor i, DbCommand t, DbCommandInterceptionContext1 c) 在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) 在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) 在 System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) 在 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) --- 内部异常堆栈跟踪的末尾 --- 在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 在 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) 在 System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__6() 在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) 在 System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__5() 在 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 operation) 在 System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) 在 System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() 在 System.Data.Entity.Internal.LazyEnumerator1.MoveNext() 在 System.Collections.Generic.List1..ctor(IEnumerable1 collection) 在 System.Linq.Enumerable.ToList(IEnumerable`1 source) 在 ProductTest.SqlServerFullTextTest.FullTextTest() 位置 SqlServerFullTextTest.cs: line 28

Martin-DC commented 7 years ago

resolved with adding container.Configuration.UseDatabaseNullSemantics = true; close the issue.

chsword commented 7 years ago

请尝试

using (var container = new ProductSystemContainer(1)) { 
container.Configuration.UseDatabaseNullSemantics = true;
var text = FullTextSearchModelUtil.Contains("三星 iphone5",true);
 var q = container.Sku.Where(c => (c.Title+c.Keywords).Contains(text)); 
container.Database.Log = Console.WriteLine;
 var a = q.ToList(); 
Assert.IsTrue(a.Count>1); 

}