/// <summary>
        /// Creates a <see cref="SaveResult"/>.
        /// </summary>
        /// <returns>The save result.</returns>
        public SaveResult ToSaveResult()
        {
            var entities    = new List <object>();
            var deletedKeys = new List <EntityKey>();

            foreach (var entityInfo in SaveMap.SelectMany(o => o.Value))
            {
                var state = entityInfo.EntityState;
                if (state != EntityState.Detached)
                {
                    entities.Add(entityInfo.ClientEntity);
                }

                if (state == EntityState.Deleted || state == EntityState.Detached)
                {
                    deletedKeys.Add(new EntityKey(
                                        BreezeHelper.GetBreezeTypeFullName(entityInfo.EntityType),
                                        entityInfo.GetIdentifierValues()));
                }
            }

            return(new SaveResult
            {
                Entities = entities,
                KeyMappings = KeyMappings,
                DeletedKeys = deletedKeys
            });
        }
Example #2
0
 public SaveResult ToSaveResult()
 {
     WasUsed = true; // try to prevent reuse in subsequent SaveChanges
     if (EntityErrors != null)
     {
         return(new SaveResult()
         {
             Errors = EntityErrors.Cast <object>().ToList()
         });
     }
     else
     {
         var entities = SaveMap.SelectMany(kvp => kvp.Value.Where(ei => (ei.EntityState != EntityState.Detached))
                                           .Select(entityInfo => entityInfo.Entity)).ToList();
         var deletes = SaveMap.SelectMany(kvp => kvp.Value
                                          .Where(ei => (ei.EntityState == EntityState.Deleted || ei.EntityState == EntityState.Detached))
                                          .Select(entityInfo =>
                                                  new EntityKey(entityInfo.Entity, ContextProvider.GetKeyValues(entityInfo))))
                       .ToList();
         return(new SaveResult()
         {
             Entities = entities, KeyMappings = KeyMappings, DeletedKeys = deletes
         });
     }
 }
Example #3
0
        public SaveResult ToSaveResult()
        {
            WasUsed = true; // try to prevent reuse in subsequent SaveChanges
            if (EntityErrors != null)
            {
                return(new SaveResult()
                {
                    Errors = EntityErrors.Cast <Object>().ToList()
                });
            }
            else
            {
                var entities = SaveMap.SelectMany(kvp => kvp.Value.Where(ei => (ei.EntityState != EntityState.Detached))
                                                  .Select(entityInfo => entityInfo.Entity)).ToList();

                // we want to stub off any navigation properties here, but how to do it quickly.
                // entities.ForEach(e => e
                var deletes = SaveMap.SelectMany(kvp => kvp.Value.Where(ei => (ei.EntityState == EntityState.Deleted || ei.EntityState == EntityState.Detached))
                                                 .Select(entityInfo => new EntityKey(entityInfo.Entity, ContextProvider.GetKeyValues(entityInfo)))).ToList();
                return(new SaveResult()
                {
                    Entities = entities, KeyMappings = KeyMappings, DeletedKeys = deletes
                });
            }
        }
Example #4
0
 public SaveResult ToSaveResult()
 {
     if (EntityErrors != null)
     {
         return(new SaveResult()
         {
             Errors = EntityErrors.Cast <Object>().ToList()
         });
     }
     else
     {
         var entities = SaveMap.SelectMany(kvp => kvp.Value.Select(entityInfo => entityInfo.Entity)).ToList();
         return(new SaveResult()
         {
             Entities = entities, KeyMappings = KeyMappings
         });
     }
 }
Example #5
0
 public SaveResult ToSaveResult()
 {
     WasUsed = true; // try to prevent reuse in subsequent SaveChanges
     if (EntityErrors != null)
     {
         return(new SaveResult()
         {
             Errors = EntityErrors.Cast <Object>().ToList()
         });
     }
     else
     {
         var entities = SaveMap.SelectMany(kvp => kvp.Value.Select(entityInfo => entityInfo.Entity)).ToList();
         return(new SaveResult()
         {
             Entities = entities, KeyMappings = KeyMappings
         });
     }
 }