public void SaveBulk(IEnumerable <ReadOnlyRelation> relations) { foreach (var hasIdentityGroup in relations.GroupBy(r => r.HasIdentity)) { if (hasIdentityGroup.Key) { // Do updates, we can't really do a bulk update so this is still a 1 by 1 operation // however we can bulk populate the object types. It might be possible to bulk update // with SQL but would be pretty ugly and we're not really too worried about that for perf, // it's the bulk inserts we care about. foreach (var relation in hasIdentityGroup) { var dto = RelationFactory.BuildDto(relation); Database.Update(dto); } } else { // Do bulk inserts var dtos = hasIdentityGroup.Select(RelationFactory.BuildDto); Database.InsertBulk(dtos); } } }
protected override void PersistUpdatedItem(IRelation entity) { ((EntityBase)entity).UpdatingEntity(); var factory = new RelationFactory(entity.RelationType); var dto = factory.BuildDto(entity); Database.Update(dto); entity.ResetDirtyProperties(); }
protected override void PersistUpdatedItem(IRelation entity) { entity.UpdatingEntity(); var dto = RelationFactory.BuildDto(entity); Database.Update(dto); PopulateObjectTypes(entity); entity.ResetDirtyProperties(); }
protected override void PersistNewItem(IRelation entity) { ((EntityBase)entity).AddingEntity(); var factory = new RelationFactory(entity.RelationType); var dto = factory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; entity.ResetDirtyProperties(); }
protected override void PersistNewItem(IRelation entity) { entity.AddingEntity(); var dto = RelationFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; PopulateObjectTypes(entity); entity.ResetDirtyProperties(); }
public void Save(IEnumerable <IRelation> relations) { foreach (var hasIdentityGroup in relations.GroupBy(r => r.HasIdentity)) { if (hasIdentityGroup.Key) { // Do updates, we can't really do a bulk update so this is still a 1 by 1 operation // however we can bulk populate the object types. It might be possible to bulk update // with SQL but would be pretty ugly and we're not really too worried about that for perf, // it's the bulk inserts we care about. var asArray = hasIdentityGroup.ToArray(); foreach (var relation in hasIdentityGroup) { relation.UpdatingEntity(); var dto = RelationFactory.BuildDto(relation); Database.Update(dto); } PopulateObjectTypes(asArray); } else { // Do bulk inserts var entitiesAndDtos = hasIdentityGroup.ToDictionary( r => // key = entity { r.AddingEntity(); return(r); }, RelationFactory.BuildDto); // value = DTO foreach (var dto in entitiesAndDtos.Values) { Database.Insert(dto); } // All dtos now have IDs assigned foreach (var de in entitiesAndDtos) { // re-assign ID to the entity de.Key.Id = de.Value.Id; } PopulateObjectTypes(entitiesAndDtos.Keys.ToArray()); } } }