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

B M-A 361 Reputation points


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;  

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,

Microsoft Technologies based on the .NET software framework.
3,165 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,941 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 52,496 Reputation points

    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