How to update multiple tables using one query in Entity Framework?

B M-A 361 Reputation points
2022-07-15T12:31:40.123+00:00

Hello,

I want to update three table with one Query in Entity Framework:

Customer_Identification                   Region                        Customer Account  
| Id                                         |Region_Id                   |Customer Id  
| Name                                       |Region_Name                 |Bank_Name  
| Address                                                                 |Bank Account  
| Region_Id  
  

I created a class Customer with all fields required and I used a join query to select what information I want to
update in database.
I try to update changes in this way :

dataContext.Entry( Customer).State = System.Data.Entity.EntityState.Modified;  
dataContext.SaveChanges();  

I receive the following exception :
The entity type DbQuery`1 is not part of the model for the current context.
How is possible to update database without using multiple queries?

Best regards,

Developer technologies .NET Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-07-18T18:11:43.62+00:00

    projections (objects mapped from a query) are not updatable.

    only DbSets defined in the DbContext that are mapped to a table (or updatable view) support updates.

    note: sql databases do not support updating multiple tables in a single statement.

    0 comments No comments

Your answer

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