Share via

DbQuery not available in entity framework core 6

Firke, Yogesh (Cognizant) 0 Reputation points
2023-04-05T06:28:59.0566667+00:00
public static IQueryable AsNoTracking(this IQueryable source)
{
    var asDbQuery = source as DbQuery;
    return asDbQuery != null ? asDbQuery.AsNoTracking() : CommonAsNoTracking(source);
}


mockSet.Setup(x => x.AsNoTracking()).Returns(mockSet.Object);
Developer technologies | .NET | Entity Framework Core

1 answer

Sort by: Most helpful
  1. Jack J Jun 25,306 Reputation points
    2023-04-05T09:16:31.9266667+00:00

    @Firke, Yogesh (Cognizant),Welcome to Microsoft Q&A, based on the Microsoft Learning Query types are consolidated with entity types, Query types have some changes after ef core 3.0. I recommend that you could try the following code to replace DbSet<> with DbQuery.

     public static IQueryable AsNoTracking(this IQueryable source)
            {
                var asDbQuery = source as DbSet<Teacher>;
                return asDbQuery != null ? asDbQuery.AsNoTracking() : CommonAsNoTracking(source);
            }
    
    

    Hope my solution could help you. Best Regards, Jack If the answer is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.