当前位置: 首页>>代码示例>>C#>>正文


C# ObjectContext.SaveChanges方法代码示例

本文整理汇总了C#中ObjectContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContext.SaveChanges方法的具体用法?C# ObjectContext.SaveChanges怎么用?C# ObjectContext.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectContext的用法示例。


在下文中一共展示了ObjectContext.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddNewUser

        public void AddNewUser(string firstname, string surname, string email, string description, string username, string password, byte[] imagebyte, string imgtype)
        {
            using (ObjectContext context = new ObjectContext(_connectionString))
            {
                var users = context.CreateObjectSet<User>();
                int maxId = users.Any() ? users.Max(x => x.Id) : 1;

                int pictureId = _pictureRepository.AddPicture(imagebyte, imgtype, string.Empty);

                User newUser = new User()
                {
                    Id = +maxId,
                    Firstname = firstname,
                    Surname = surname,
                    Email = email,
                    DateRegister = DateTime.Now,
                    Description = description,
                    Username = username,
                    Password = password,
                    isEnable = true,
                    isAdmin = false,
                    PictureId = pictureId
                };

                users.AddObject(newUser);
                context.SaveChanges();
            };
        }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:28,代码来源:EFUserRepository.cs

示例2: SetArticleContent

 public void SetArticleContent(string content)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         Article article = context.CreateObjectSet<Article>().Single(x => x.Id == 1);
         article.Content = content;
         context.SaveChanges();
     }
 }
开发者ID:RomanOrv,项目名称:HelpForSick,代码行数:9,代码来源:EFArticleRepository.cs

示例3: ChangePublishingStatus

 public void ChangePublishingStatus(Article article)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         var oldArticle = context.CreateObjectSet<Article>().Single(x => x.Id ==article.Id);
         oldArticle.Published = article.Published;
         context.SaveChanges();
     }
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:9,代码来源:EFArticleRepository.cs

示例4: SetPersonPageInfo

 public void SetPersonPageInfo(string mainInfo, string diagnosis, string moneyInfo)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         PersonPageInfo article = context.CreateObjectSet<PersonPageInfo>().Single(x => x.Id == 1);
         article.MainInfo = mainInfo;
         article.Diagnosis = diagnosis;
         article.MoneyInfo = moneyInfo;
         context.SaveChanges();
     }
 }
开发者ID:RomanOrv,项目名称:HelpForSick,代码行数:11,代码来源:EFPersonPageInfoRepository.cs

示例5: SaveChanges

        protected bool SaveChanges(ObjectContext context)
        {
            try
            {
                int i = context.SaveChanges();

                if (i == 0)
                    return false;

                return true;
            }
            catch (Exception ex)
            {
                throw new EntityContextException("SaveChanges failed.", ex);
            }
        }
开发者ID:cmsni,项目名称:fullUploadUniteCmsSoccer,代码行数:16,代码来源:ContextBase.cs

示例6: DoWork

        public void DoWork()
        {
            var context = new ObjectContext(_connectionString);

            var firstMember = context.CreateObjectSet<Member>()
                .OrderByDescending(m => m.firstName)
                .First();

            firstMember.licenseExpiration = firstMember.licenseExpiration.AddDays(1);

            var lastMember = context.CreateObjectSet<Member>()
                .OrderBy(m => m.licenseExpiration)
                .First();

            lastMember.firstName = "Jacob";

            context.SaveChanges();
        }
开发者ID:jascenci,项目名称:MS,代码行数:18,代码来源:UnitOfWork.cs

示例7: AddNewComment

        public void AddNewComment(string content, int authorId, int articleId)
        {
            using (ObjectContext context = new ObjectContext(_connectionString))
            {
                var comments = context.CreateObjectSet<Comment>();
                int maxId = comments.Any() ? comments.Max(x => x.Id) : 1;

                Comment comment = new Comment()
                {
                    Id = +maxId,
                    Content = content,
                    ArticleId = articleId,
                    AuthorId = authorId,
                    CommDate = DateTime.Now
                };
                comments.AddObject(comment);
                context.SaveChanges();
            }
        }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:19,代码来源:EFCommentRepository.cs

示例8: CreateArticle

        public void CreateArticle(string title)
        {
            using (ObjectContext context = new ObjectContext(_connectionString))
            {
                var articles = context.CreateObjectSet<Article>();
                int maxId = articles.Any() ? articles.Max(x => x.Id) : 1;

                Article newArticle = new Article()
                {
                    Id = +maxId,
                    Title = title,
                    Content = string.Empty,
                    CreationTime = DateTime.Now,
                    Published = true
                };

                articles.AddObject(newArticle);
                context.SaveChanges();
            };
        }
开发者ID:RomanOrv,项目名称:HelpForSick,代码行数:20,代码来源:EFArticleRepository.cs

示例9: TrackDirectUrlHistory

        public static void TrackDirectUrlHistory(string newDirectUrl, EntityTypeId entityTypeId, string targetDirectUrl, int targetId, ObjectContext objectContext)
        {
            if (newDirectUrl != targetDirectUrl)
            {

                var directUrlHistoryContext = objectContext.CreateObjectSet<DirectUrlHistory>();

                // If the new direct URL exists in history, remove from history
                var newDirectUrlHistory = directUrlHistoryContext.SingleOrDefault(d => d.EntityTypeId == (int)entityTypeId && (d.DirectUrl == newDirectUrl));

                if (newDirectUrlHistory != null)
                    directUrlHistoryContext.DeleteObject(newDirectUrlHistory);

                // Add old direct URL to the history
                if (!string.IsNullOrEmpty(targetDirectUrl))
                {
                    var oldDirectUrlHistory = new DirectUrlHistory() { EntityTypeId = (int)entityTypeId, EntityId = targetId, DirectUrl = targetDirectUrl, DateAdded = DateTime.Now };
                    directUrlHistoryContext.AddObject(oldDirectUrlHistory);
                }
                objectContext.SaveChanges();
            }
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:22,代码来源:DirectUrlHistoryUtility.cs

示例10: AddExternalIdMapping

        public static void AddExternalIdMapping(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target)
        {
            if (!string.IsNullOrEmpty(source.OccurrenceExternalId))
            {
                var mappingExists = context.CreateObjectSet<DataImportEntityIdMap>()
                    .Any(m => m.EntityName == "EventOccurrence" &&
                    m.InternalId == target.Id &&
                    m.ExternalId == source.OccurrenceExternalId);

                if (!mappingExists)
                {
                    context.AddObject("DataImportEntityIdMaps", new DataImportEntityIdMap
                    {
                        EntityName = "EventOccurrence",
                        DataImportId = 2,
                        InternalId = target.Id,
                        ExternalId = source.OccurrenceExternalId
                    });
                    context.SaveChanges();
                }
            }
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:22,代码来源:EventOccurrenceApiHelper.cs

示例11: AddPicture

        public int AddPicture(byte[] data, string mimetype, string src)
        {
            int imgId = 0;

            using (ObjectContext context = new ObjectContext(this._connectionString))
            {
                var images = context.CreateObjectSet<Picture>();

                if (!images.Any(x => x.FileData == data))
                {
                    int maxId = images.Any() ? images.Max(x => x.Id) : 1;
                    Picture newImage = new Picture() { Id = +maxId, FileData = data, ImageMimeType = mimetype, Src = src };
                    imgId = newImage.Id;
                    images.AddObject(newImage);
                    context.SaveChanges();
                }
                else
                {
                    imgId = images.Single(x => x.FileData == data).Id;
                }
            }

            return imgId;
        }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:24,代码来源:EFPictureRepository.cs

示例12: RebuildGeneratedKeywords

        private static void RebuildGeneratedKeywords(IEnumerable<int> providerIds, string oldCustomKeywords, ObjectContext objectContext, bool isBulkUpdate)
        {
            var settingsManager = ServiceLocator.GetInstance<ISettingsManager>();

            // Check if automated taxonomy is enabled for providers
            var automatedTaxonomyEnabled = GetBooleanKeywordSetting(settingsManager, Utils.Common.Constants.KeywordsAutomatedTaxonomyProviders);

            // Get excluded words
            _globalExcludedKeywords = GetExcludedWordsAsArray(settingsManager);

            // Determine the keyword generator configuration
            var keywordGeneratorType = GetKeywordGeneratorType(settingsManager);

            foreach (var providerId in providerIds)
            {
                switch (keywordGeneratorType)
                {
                    case KeywordGeneratorType.None:
                        BuildKeywordsWithNoGenerator(providerId, objectContext);
                        break;
                    case KeywordGeneratorType.Internal:
                        if (automatedTaxonomyEnabled)
                            BuildKeywordsWithInternalGenerator(providerId, objectContext);
                        else
                            BuildKeywordsWithNoGenerator(providerId, objectContext);
                        break;
                    case KeywordGeneratorType.InternalWithSynonyms:
                        if (automatedTaxonomyEnabled)
                        {
                            // For performance reasons, only generate keywords with synonyms during bulk updates
                            if (isBulkUpdate)
                            {
                                var provider = BuildKeywordsWithInternalGenerator(providerId, objectContext);
                                BuildKeywordsWithInternalSynonymGenerator(provider, settingsManager);
                            }
                        }
                        else
                        {
                            BuildKeywordsWithNoGenerator(providerId, objectContext);
                        }
                        break;
                    case KeywordGeneratorType.External:
                        BuildKeywordsWithExternalGenerator(providerId, oldCustomKeywords, objectContext);
                        break;
                }
            }

            // Persist keywords
            objectContext.SaveChanges();
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:50,代码来源:KeywordGenerator.cs

示例13: SaveChanges

        protected void SaveChanges(ObjectContext entities)
        {
            int affectedRows = entities.SaveChanges();

            if (affectedRows == 0)
            {
                throw new DataAccessException(DataAccessErrorCode.RecordNotFound);
            }
        }
开发者ID:southapps,项目名称:Libraries,代码行数:9,代码来源:DataAccessObject.cs

示例14: PublishOrgUnits

        /// <summary>
        /// Publishes the specified org unit.
        /// </summary>
        /// <param name="objectContext">The object context.</param>
        /// <param name="orgUnitId">The org unit ID.</param>
        /// <remarks>Calls SaveChanges on the object context.</remarks>
        public static void PublishOrgUnits(ObjectContext objectContext, int? orgUnitId)
        {
            var disabledOrgUnits = new Collection<int>();

            // Create object sets
            var orgUnitObjectSet = objectContext.CreateObjectSet<OrgUnit>()
                .AsNoTracking()
                .Include("Schedules")
                .Include("OrgUnitInsurances")
                .Include("OrgUnitTypeAssociations")
                .Include("OrgUnitADGroups")
                .Include("OrgUnitServices");
            var orgUnitPubObjectSet = objectContext.CreateObjectSet<OrgUnitPublished>();
            var orgUnitAssocObjectSet = objectContext.CreateObjectSet<OrgUnitAssociation>();
            var orgUnitAssocPubObjectSet = objectContext.CreateObjectSet<OrgUnitAssociationPublished>();

            // Retrieving all existing org units
            var orgUnits = (from o in orgUnitObjectSet
                            select o).ToArray();

            // Retrieving all existing org units associations
            var orgUnitAssocs = (from a in orgUnitAssocObjectSet
                                 select a).ToArray();

            // Get org units sub-set to publish
            IEnumerable<OrgUnit> orgUnitsToPublish = GetOrgUnitsToPublish(orgUnitObjectSet, orgUnitAssocPubObjectSet, orgUnitId);

            // For each org unit
            foreach (OrgUnit orgUnit in orgUnitsToPublish)
            {
                // Create a new published org unit from original and set non-inheritable information
                var orgUnitPub = new OrgUnitPublished
                {
                    Id = orgUnit.Id,
                    Name = orgUnit.Name,
                    IsEnabled = orgUnit.IsEnabled,
                    LinkedOrgUnitId = orgUnit.LinkedOrgUnitId,
                    Keywords = orgUnit.Keywords,
                    CustomKeywords = orgUnit.CustomKeywords,
                    Custom1 = orgUnit.Custom1,
                    Custom2 = orgUnit.Custom2,
                    Custom3 = orgUnit.Custom3,
                    DynamicColumnData = orgUnit.DynamicColumnData,
                    SeoPageTitle = orgUnit.SeoPageTitle,
                    SeoPageDescription = orgUnit.SeoPageDescription,
                    SeoCustomMetaTags = orgUnit.SeoCustomMetaTags,
                    SeoH1tag = orgUnit.SeoH1tag,
                    SeoPrimaryKeyword = orgUnit.SeoPrimaryKeyword,
                    SeoSecondaryKeyword = orgUnit.SeoSecondaryKeyword,
                    SeoCanonicalUrl = orgUnit.SeoCanonicalUrl,
                    HasCustomCoordinates = orgUnit.HasCustomCoordinates,
                    PotentialEventLocation = orgUnit.PotentialEventLocation,
                    Description = orgUnit.Description
                };

                // Resolve all remaining information for published org unit

                orgUnitPub = ResolvePublishedOrgUnit(orgUnit, orgUnitPub, orgUnits, orgUnitAssocs, disabledOrgUnits);

                // Track disabled published org units for future reference
                if (orgUnitPub.IsEnabled != null && !orgUnitPub.IsEnabled.Value)
                    disabledOrgUnits.Add(orgUnit.Id);

                // Save changes to object set
                SavePublishedOrgUnit(orgUnitPubObjectSet, orgUnitPub);
            }

            objectContext.SaveChanges();
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:75,代码来源:PublishOrgUnitsHelper.cs

示例15: BuildNewOccurrence

        public static EventOccurrence BuildNewOccurrence(ObjectContext objectContext, int newEventId, EventOccurrence item)
        {
            var newOccurrence = new EventOccurrence
            {
                ContactName = item.ContactName,
                ContactEmail = item.ContactEmail,
                ContactPhone = item.ContactPhone,
                ContactPhoneExtension = item.ContactPhoneExtension,
                Cost = item.Cost,
                CostCenter = item.CostCenter,
                OrgUnitId = item.OrgUnitId,
                MaximumAttendees = item.MaximumAttendees,
                LastUpdated = System.DateTime.UtcNow,
                PaymentProcessorConfigurationId = item.PaymentProcessorConfigurationId,
                IsRegistrationEnabled = item.IsRegistrationEnabled,
                IsNotificationListEnabled = item.IsNotificationListEnabled,
                IsNotifyContactEnabled = item.IsNotifyContactEnabled,
                SpecialInstructions = item.SpecialInstructions,
                LocationOrgUnitId = item.LocationOrgUnitId,
                LocationName = item.LocationName,
                Address1 = item.Address1,
                Address2 = item.Address2,
                City = item.City,
                PostalCode = item.PostalCode,
                StateId = item.StateId,
                CountryId = item.CountryId,
                Latitude = item.Latitude,
                Longitude = item.Longitude,
                IsGuestDemographicInfoRequired = item.IsGuestDemographicInfoRequired
            };

            newOccurrence.SetPresenter(item.Presenter);
            newOccurrence.SetIsEnabled(item.IsEnabled);
            newOccurrence.SetEventId(newEventId);

            newOccurrence.SetAddress1(item.Address1);
            newOccurrence.SetAddress2(item.Address2);

            newOccurrence.SetRegistrationDates(item.RegistrationStartDate, item.RegistrationEndDate);

            if (item.IsPriceScheduleEnabled)
                newOccurrence.EnablePricingSchedule();
            else
                newOccurrence.DisablePricingSchedule();

            CaptureCostScheduleData(item, newOccurrence);

            objectContext.AddObject("EventOccurrences", newOccurrence);
            objectContext.SaveChanges();

            //event occurrence documents
            foreach (var doc in item.EventOccurrencesDocuments)
            {
                var newDoc = new EventOccurrencesDocument()
                {
                    DocumentPath = doc.DocumentPath,
                    EventOccurrence = newOccurrence
                };
                newOccurrence.EventOccurrencesDocuments.Add(newDoc);
            }

            //event occurrence dates
            foreach (var dateItem in item.EventOccurrenceDates)
            {
                newOccurrence.AddOccurrenceDate(dateItem.StartDate, dateItem.EndDate);
            }
            objectContext.SaveChanges();

            return newOccurrence;
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:70,代码来源:CopyEventOccurrenceHelper.cs


注:本文中的ObjectContext.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。