Click here to Skip to main content
15,886,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have this method to update 2 tables (parent and child) :
C#
public override void Update(ArCollectiveBilling entity)
        {
            var existingEntity = (from e in Entities.Include("ArCollectiveBillingLines")
                                where e.CollectiveBillingId == entity.CollectiveBillingId
                                select e).FirstOrDefault();

            // Cannot Update if Entity Doesn't exists in database
            if (existingEntity == null)
                throw (new InvalidOperationException("Entity Doesnt exist in database"));

            if (existingEntity.Vers != entity.Vers)
                throw (new OptimisticConcurrencyException("Another user has updated the database"));

            // Update entity Vers and Audit Data field
            entity.LastModDateTime = DateTime.Now;
            entity.CreateDateTime = existingEntity.CreateDateTime;
            entity.CreateUser = existingEntity.CreateUser;
            entity.Vers = existingEntity.Vers + 1;

            // Update Standard Code Type
            existingEntity.Merge(entity);            
            Entities.ApplyCurrentValues(existingEntity);
        }


code above makes EF 4.1 send query to update parent table
and insert 300 items child after delete it all

is this behavior of Entity Framework?

could i update parent table (Entities) only without send query to delete and insert 300 items on child (ArCollectiveBillingLines) table?
Posted
Updated 31-May-15 16:02pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900