EF core在App Service stg env中重命名表后对象名称无效



我在本地运行我的应用程序,在dev-env和prd-env中都没有问题,但在stg-env中我得到了这个"无效的对象名称"bls.TaskFeedReactions";例外

我把表从";TaskFeedReactions";至";FeedReactions";,迁移丢弃了表";TaskFeedReactions";并创建了新的";FeedReactions";,在每个env DB(dev(也被localhost使用(、stg和prd(中;FeedReactions";,同样在DbContext中,我有这样的:

EntityTypeBuilder<FeedReactionModel> feedReactions = modelBuilder.Entity<FeedReactionModel>();
feedReactions.ToTable("FeedReactions", BLSchema);
.
.

为什么stg环境正在创建一个使用旧名称"的查询;TaskFeedReactions";我该怎么修?

最佳

不知何故,EF Core在这个环境中缓存了查询,而重新启动或重新部署应用程序并没有清理缓存的查询,也没有在更新了表名的情况下重新创建新查询。

因此,为了解决这个问题,我评论了访问重命名表的查询部分:

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();

在stg-env中重新部署了它,然后删除了注释并重新部署。

它为我解决了问题。

相关内容

最新更新