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


C# ObjectContext.CreateObjectSet方法代码示例

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


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

示例1: FindAssociatedOrgUnits

        /// <summary>
        /// Finds the associated org units.
        /// </summary>
        /// <param name="objectContext">The object context.</param>
        /// <param name="dto">The DTO.</param>
        /// <returns>An enumerable of the associated Org Unit IDs</returns>
        public static IEnumerable<int> FindAssociatedOrgUnits(ObjectContext objectContext, AssociatedOrgUnitsDto dto)
        {
            List<int> relatedUnits = new List<int>();

            var orgUnitAssociationPublished = objectContext.CreateObjectSet<OrgUnitAssociationPublished>();
            var orgUnitPublished = objectContext.CreateObjectSet<OrgUnitPublished>();

            if (dto.OrganizationalUnitId.HasValue)
            {
                var orgUnitIdAsList = new List<int>() { dto.OrganizationalUnitId.Value };

                if (dto.DescendantOption != DescendantOption.NoDescendants)
                {
                    var newUnits = GetDescendants(orgUnitIdAsList, dto.DescendantOption, orgUnitAssociationPublished, orgUnitPublished);
                    AddUnitsToList(ref relatedUnits, newUnits);
                }

                if (dto.LinkedOption != LinkedOption.NoLinkedUnits)
                {
                    var newUnits = GetLinkedUnits(orgUnitIdAsList, dto.LinkedOption, orgUnitAssociationPublished, orgUnitPublished);
                    AddUnitsToList(ref relatedUnits, newUnits);
                }

                //add the current org unit
                AddUnitsToList(ref relatedUnits, new List<int> { dto.OrganizationalUnitId.Value });
            }
            return relatedUnits.ToArray();
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:34,代码来源:AssociatedOrgUnitFinder.cs

示例2: GetAllUsers

 public List<User> GetAllUsers()
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         return context.CreateObjectSet<User>().ToList();
     }
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:7,代码来源:EFUserRepository.cs

示例3: BuildKeywordsWithInternalGenerator

        private static Service BuildKeywordsWithInternalGenerator(int serviceId, ObjectContext objectContext)
        {
            // Fetch service entity
            var service = objectContext.CreateObjectSet<Service>().Single(s => s.Id == serviceId);

            // Sanitize custom keywords and build generated keywords
            var generatedKeywords = new StringBuilder();
            var delimiter = Utils.Common.Keywords.KeywordUtils.ResolveKeywordDelimiter(service.CustomKeywords);

            service.CustomKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(service.CustomKeywords, _excludedWords, delimiter);

            // Append custom keywords
            if (service.CustomKeywords != null)
                generatedKeywords.Append(service.CustomKeywords);

            // Append service name
            if (service.Name != null)
                generatedKeywords.Append(delimiter + service.Name);

            // Sanitize and persist keywords
            var sanitizedKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(generatedKeywords.ToString(), _excludedWords);

            service.Keywords = sanitizedKeywords;
            return service;
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:25,代码来源:KeywordGenerator.cs

示例4: GetPicture

 public Picture GetPicture(string src)
 {
     using (ObjectContext context = new ObjectContext(this._connectionString))
     {
         return context.CreateObjectSet<Picture>().Single(x=>x.Src == src);
     }
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:7,代码来源:EFPictureRepository.cs

示例5: BuildKeywordsWithInternalGenerator

        private static Event BuildKeywordsWithInternalGenerator(int eventId, ObjectContext objectContext)
        {
            // Fetch event entity
            var eventEntity = objectContext.CreateObjectSet<Event>().Include("EventTopicAssociations.EventTopic").Single(e => e.Id == eventId);

            // Sanitize custom keywords and build generated keywords
            var generatedKeywords = new StringBuilder();
            var delimiter = Utils.Common.Keywords.KeywordUtils.ResolveKeywordDelimiter(eventEntity.CustomKeywords);

            eventEntity.CustomKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(eventEntity.CustomKeywords, _excludedWords, delimiter);

            // Append custom keywords
            if (eventEntity.CustomKeywords != null)
                generatedKeywords.Append(eventEntity.CustomKeywords);

            // Append event topics
            if (eventEntity.EventTopicAssociations.Count() > 0)
                generatedKeywords.Append(delimiter + string.Join(",", eventEntity.EventTopicAssociations.Select(e => e.EventTopic.Name).ToArray()));

            // Sanitize and persist keywords
            var sanitizedKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(generatedKeywords.ToString(), _excludedWords);

            eventEntity.Keywords = sanitizedKeywords;

            return eventEntity;
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:26,代码来源:KeywordGenerator.cs

示例6: BuildKeywordsWithInternalGenerator

        private static OrgUnit BuildKeywordsWithInternalGenerator(int orgUnitId, ObjectContext objectContext)
        {
            // Fetch orgUnit entity with related data
            var orgUnitSet = objectContext.CreateObjectSet<OrgUnit>()
                .Include("OrgUnitServices.Service")
                .Include("OrgUnitTypeAssociations.OrgUnitType");

            var orgUnit = orgUnitSet.Single(o => o.Id == orgUnitId);

            // Sanitize custom keywords and build generated keywords
            var generatedKeywords = new StringBuilder();
            var delimiter = Utils.Common.Keywords.KeywordUtils.ResolveKeywordDelimiter(orgUnit.CustomKeywords);

            orgUnit.CustomKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(orgUnit.CustomKeywords, _excludedWords, delimiter);

            // Append custom keywords
            if (orgUnit.CustomKeywords != null)
                generatedKeywords.Append(orgUnit.CustomKeywords);

            // Append org unit type names
            generatedKeywords.Append(delimiter + String.Join(delimiter, orgUnit.OrgUnitTypeAssociations.Select(t => t.OrgUnitType.Name)));

            // Append service names
            generatedKeywords.Append(delimiter + String.Join(delimiter, orgUnit.OrgUnitServices.Select(s => s.Service.Name)));

            // Sanitize and persist keywords
            var sanitizedKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(generatedKeywords.ToString(), _excludedWords);

            orgUnit.Keywords = sanitizedKeywords;

            return orgUnit;
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:32,代码来源:KeywordGenerator.cs

示例7: GetPersonPageInfo

 public PersonPageInfo GetPersonPageInfo()
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         return context.CreateObjectSet<PersonPageInfo>().FirstOrDefault(x => x.Id == 1);
     }
 }
开发者ID:RomanOrv,项目名称:HelpForSick,代码行数:7,代码来源:EFPersonPageInfoRepository.cs

示例8: GetArticle

 public Article GetArticle()
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         return context.CreateObjectSet<Article>().FirstOrDefault(x => x.Id == 1);
     }
 }
开发者ID:RomanOrv,项目名称:HelpForSick,代码行数:7,代码来源:EFArticleRepository.cs

示例9: ValidateUserIntegrationEntity

        /// <summary>
        /// Validates the user integration entity.
        /// </summary>
        /// <param name="userIntegration">The user integration.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static StatusMessage ValidateUserIntegrationEntity(UserIntegrationDto userIntegration, ObjectContext context)
        {
            const int maximumExternalIdLength = 50;
            const int maximumExternalSystemLength = 500;

            if (userIntegration == null)
            {
                return StatusMessage.MissingData;
            }
            if (userIntegration.UserId == 0)
            {
                return StatusMessage.InvalidData;
            }
            if (string.IsNullOrEmpty(userIntegration.ExternalId) || userIntegration.ExternalId.Length > maximumExternalIdLength)
            {
                return StatusMessage.InvalidData;
            }
            if (string.IsNullOrEmpty(userIntegration.ExternalSystem) || userIntegration.ExternalSystem.Length > maximumExternalSystemLength)
            {
                return StatusMessage.InvalidData;
            }
            if (context.CreateObjectSet<DAL.UserIntegration>().Count(u => u.UserId == userIntegration.UserId && u.ExternalSystem == userIntegration.ExternalSystem && u.Id != userIntegration.Id) > 0)
            {
                return StatusMessage.DuplicateData;
            }

            return StatusMessage.Success;
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:34,代码来源:UserIntegrationValidator.cs

示例10: 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

示例11: CheckUnicueUsername

 public bool CheckUnicueUsername(string username)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         bool isExists = context.CreateObjectSet<User>().Any(x => x.Username == username);
         return isExists ? false : true;
     }
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:8,代码来源:EFUserRepository.cs

示例12: GetPublished

 public List<Article> GetPublished()
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         return context.CreateObjectSet<Article>()
             .Where(u => u.Published == true).ToList();
     }
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:8,代码来源:EFArticleRepository.cs

示例13: CheckUniqueTitle

 public bool CheckUniqueTitle(string title)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         bool isExists = context.CreateObjectSet<Article>().Any(u => u.Title == title);
         return !isExists;
     };
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:8,代码来源:EFArticleRepository.cs

示例14: GetArticleComments

 public Comment[] GetArticleComments(int articleId)
 {
     using (ObjectContext context = new ObjectContext(_connectionString))
     {
         return context.CreateObjectSet<Comment>()
             .Where(u => u.ArticleId == articleId).ToArray();
     }
 }
开发者ID:RomanOrv,项目名称:BlogProject,代码行数:8,代码来源:EFCommentRepository.cs

示例15: ResolveOrgUnitId

 protected static int? ResolveOrgUnitId(ObjectContext context, string internalId, string externalId)
 {
     int? orgUnitId = null;
     if (!string.IsNullOrEmpty(externalId))
     {
         var mapping = context.CreateObjectSet<DataImportEntityIdMap>().FirstOrDefault(m => m.EntityName == "OrgUnit" && m.ExternalId == externalId);
         if (mapping == null)
             throw new BusinessException("Unknown OrgUnitExternalId: " + externalId);
         orgUnitId = mapping.InternalId;
     }
     else
     {
         orgUnitId = GetNullableInt(internalId);
     }
     if (orgUnitId.HasValue && !context.CreateObjectSet<OrgUnit>().Any(ou => ou.Id == orgUnitId.Value))
         throw new BusinessException("Invalid OrgUnitID:" + orgUnitId.Value.ToString(CultureInfo.InvariantCulture));
     return orgUnitId;
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:18,代码来源:EventApiHelperBase.cs


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