0

In the project we add a new entity into a table using EF 6.0 with the following steps: context create, new entity create, entity added to the entity set, fields update, context SaveChanges. I don't know if it is important or not - one of the field is full text index.

In a very short time we creates another context and sends a sql query with the following method:

context.<Table>.SqlQuery( selectStr, sqlParameters) 

In the query there are several where query part using the full text search capability - this is why we creates the sql query as a string and do not use LINQ:

Contains(<FieldName>, @p0)

The problem we face with that the query cannot find the entity inserted recently, but after several try (and some seconds) voilá - the entity can be found in the result set.

What should we do to find the item for the very first time?

Zoltan Hernyak
  • 989
  • 1
  • 14
  • 35
  • I found out that the full text index can be the problem, as the entity can be found in the db just after the insertion using a non full text search query, but the queries using the full text index cannot find it for a few seconds. – Zoltan Hernyak Nov 11 '15 at 13:52
  • May this article talks about this problem http://stackoverflow.com/questions/2727911/how-can-i-know-when-sql-full-text-index-population-is-finished – Zoltan Hernyak Nov 11 '15 at 14:09

1 Answers1

0

This usually occurs if:

  • Second context is nested below the first context - i.e. Service1 has first context, and also has reference to object Service2, which has second context. Problem is somewhere around the fact that the moment second context was constructed, that db entry didn't exists.
  • Also, not entirely sure on why this is the case, but other contexts sometimes fails to see changes if the first context isn't disposed, before trying to read with the 2nd one.
  • These calls (save and query) are behind a WCF service, both context are in a using (var context = new DbContext()) { ... } block. Also, I tried in the 2nd case the before sending the query I loads the entity into the memory with context..SingleOrDefault(p => p.Key == ) so the entity is in the db, and loaded by the 2nd context. But after this "hack" it still cannot be found by the query. :( Still no idea why...
    – Zoltan Hernyak Nov 11 '15 at 13:20