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,

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,647 questions
C#
C#
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.
10,648 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,731 Reputation points
    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