Example #1
0
        /// <summary>
        /// Wraps a call to EntityFramework Core Add. The call is made with a mapped entity (DataAccess.Models.Customer) instead of the domain model passed as a parameter. The DataAccess.Model is used to communicate with EF Core.
        ///
        /// EF Core Add:
        /// Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found, then null is returned.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Domain.Models.Customer</returns>
        public void Add(Domain.Models.Customer entity)
        {
            var mappedAddress = Mapper.MapAddress(entity);

            _context.Set <Address>().Add(mappedAddress);
            _context.SaveChanges();
            _context.Entry(mappedAddress).Reload();
            var mappedEntity = Mapper.MapCustomer(entity);

            mappedEntity.Address = mappedAddress.AddressId;
            _context.Set <Customer>().Add(mappedEntity);
        }
Example #2
0
 /// <summary>
 /// This method wraps a call to EF Core SaveChanges
 /// EF Core SaveChanges
 ///  Saves all changes made in this context to the database.
 /// This method will automatically call EF Core's DetectChanges() to discover any changes to entity instances before saving to the underlying database.This can be disabled via AutoDetectChangesEnabled.
 /// </summary>
 public void Save()
 {
     _context.SaveChanges();
 }