Example #1
0
        public virtual GlobalSetting GetByKey(String key)
        {
            var query = from o in Context.CreateQuery(EntityName)
                        where o.GetAttributeValue <String>(GlobalSettingEntity.KeyFieldName(_prefix)) == key
                        select new
            {
                Id            = o.GetAttributeValue <Guid>(GlobalSettingEntity.IdFieldName(_prefix)),
                Name          = o.GetAttributeValue <String>(Common.CustomNameFieldName(_prefix)),
                Key           = o.GetAttributeValue <String>(GlobalSettingEntity.KeyFieldName(_prefix)),
                Value         = o.GetAttributeValue <String>(GlobalSettingEntity.ValueFieldName(_prefix)),
                Type          = o.GetAttributeValue <OptionSetValue>(GlobalSettingEntity.TypeFieldName(_prefix)),
                ReferenceType = o.GetAttributeValue <String>(GlobalSettingEntity.ReferenceTypeFieldName(_prefix))
            };

            var array = query.ToArray();

            return(array.Any() ? new GlobalSetting(_prefix)
            {
                Id = array[0].Id,
                Key = array[0].Key,
                Name = array[0].Name,
                Value = array[0].Value,
                Type = array[0].Type.ToEnum <GlobalSettingType>() ?? GlobalSettingType.String,
                ReferenceType = array[0].ReferenceType
            } : null);
        }
Example #2
0
        public virtual IEnumerable <GlobalSetting> GetAll()
        {
            var query = from o in Context.CreateQuery(EntityName)
                        select new
            {
                Id            = o.GetAttributeValue <Guid>(GlobalSettingEntity.IdFieldName(_prefix)),
                Name          = o.GetAttributeValue <String>(Common.CustomNameFieldName(_prefix)),
                Key           = o.GetAttributeValue <String>(GlobalSettingEntity.KeyFieldName(_prefix)),
                Value         = o.GetAttributeValue <String>(GlobalSettingEntity.ValueFieldName(_prefix)),
                Type          = o.GetAttributeValue <OptionSetValue>(GlobalSettingEntity.TypeFieldName(_prefix)),
                ReferenceType = o.GetAttributeValue <String>(GlobalSettingEntity.ReferenceTypeFieldName(_prefix))
            };

            var array = query.ToArray();

            return(array
                   .Select(o => new GlobalSetting(_prefix)
            {
                Id = o.Id,
                Key = o.Key,
                Name = o.Name,
                Value = o.Value,
                Type = o.Type.ToEnum <GlobalSettingType>() ?? GlobalSettingType.String,
                ReferenceType = o.ReferenceType
            }).ToArray());
        }