0

I'm running my app locally, in dev env and also in prd env without a problem, but in stg env I get this "Invalid object name 'bls.TaskFeedReactions" exception..

I renamed the table from "TaskFeedReactions" to "FeedReactions", the migrations dropped the table "TaskFeedReactions" and created the new one "FeedReactions", in every env DB (dev(used also by localhost), stg and prd) I have the table "FeedReactions", also in the DbContext I have this:

        EntityTypeBuilder<FeedReactionModel> feedReactions = modelBuilder.Entity<FeedReactionModel>();

        feedReactions.ToTable("FeedReactions", BLSchema);
                            .
                            .

Why is stg environment creating a query that uses the old name "TaskFeedReactions" and how can I fix it?

Bests

MarchalPT
  • 1,268
  • 9
  • 28
  • Renaming a table will not update any Triggers/Procedures/Queries that have been defined for the table (or any references to it anywhere else),we need to manually update any triggers or other dependencies to reflect the new name. – Harshitha Veeramalla Mar 10 '22 at 04:40
  • @HarshithaVeeramalla-MT but why in every other environment I didn't needed to do anything else and only for stg this is happening even when I run the app locally with stg DB it works fine... – MarchalPT Mar 10 '22 at 09:50
  • Re-Deploy the app once again and check. – Harshitha Veeramalla Mar 10 '22 at 09:53

1 Answers1

0

Somehow EF Core had cached the query in this environment in a way that restarting or redeploying the app was not cleaning the cached query and recreating the new query with the table name updated.

So to solve this I commented the part of the query that accessed the renamed table:

        return await context.TaskFeedMessages
            .Where(x => x.TaskId == taskId)
            .Select(x => new TaskFeedModel
            {
                Id = x.Id,
                CreatorId = x.CreatorId,
                TaskId = x.TaskId,
                MessageType = x.MessageType,
                Text = x.Text,
                Status = x.Status,
                IsImportant = x.IsImportant,
                //ReactionsDict = new Dictionary<string, HashSet<string>>(
                //    x.Reactions.GroupBy(Y => Y.Reaction)
                //    .Select(y => new KeyValuePair<string, HashSet<string>>(
                //            y.Key, y.Select(z => z.UserId).ToHashSet()))),
                CreatedAt = x.CreatedAt
            })
            .OrderByDescending(x => x.CreatedAt)
            .Skip(skip)
            .Take(take)
            .ToListAsync();
    

Redeployed it in stg env and and then removed the comments and redeployed again.

It solved the problem for me.

MarchalPT
  • 1,268
  • 9
  • 28