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


C# Entity.CreateProperties方法代码示例

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


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

示例1: CreateBaseCommand

        private DbCommand CreateBaseCommand(Entity entity)
        {
            var sbKeys = new StringBuilder();
            var sbVals = new StringBuilder();

            var cmd = DB.CreateCommand();
            var counter = 0;
            foreach (var property in entity
                .CreateProperties(getForeignCollection: false)
                .WhereIsNotSkipped())
            {
                sbKeys.AppendFormat("{0},", property.ColumnName);
                sbVals.AppendFormat("@{0},", counter);
                AddParam(cmd, property);
                counter++;
            }
            var keys = sbKeys.ToString().Substring(0, sbKeys.Length - 1);
            var vals = sbVals.ToString().Substring(0, sbVals.Length - 1);
            var idType = "int";
            var insertedId = "SCOPE_IDENTITY()";
            if (entity.Key.Count > 1 || entity.Key.FirstOrDefault().TypeInfo.IsString)
            {
                idType = "nvarchar(max)";
                insertedId = "@" + counter;
                cmd.AddParam(entity.JoinedKeyValue);
            }
            var sql = SqlFormat.Fill(entity.TableName, keys, vals, idType, insertedId);
            cmd.CommandText = sql;

            return cmd;
        }
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:31,代码来源:RecordsCreator.cs

示例2: GetEntityWithData

        public Entity GetEntityWithData(Entity entity, params string[] key)
        {
            var keys = new object[key.Length];
            for (int i = 0; i < key.Length; i++)
            {
                keys[i] = entity.Key[i].Value.ToObject(key[i]);
            }
            var item = GetRecord(entity, keys);
            if (item == null)
            {
                _notificator.Error(IlaroAdminResources.EntityNotExist);
                return null;
            }

            var propertiesDict = item as IDictionary<string, object>;

            foreach (var property in entity.CreateProperties(false))
            {
                property.Value.Raw =
                    propertiesDict.ContainsKey(property.ColumnName.Undecorate()) ?
                    propertiesDict[property.ColumnName.Undecorate()] :
                    null;
            }

            return entity;
        }
开发者ID:Thecentury,项目名称:Ilaro.Admin,代码行数:26,代码来源:RecordsSource.cs

示例3: CreateBaseCommand

        protected virtual DbCommand CreateBaseCommand(Entity entity)
        {
            var sbKeys = new StringBuilder();

            var cmd = DB.CreateCommand();
            var counter = 0;
            var updateProperties = entity.CreateProperties(getForeignCollection: false)
                .Where(x => x.IsKey == false)
                .WhereIsNotSkipped().ToList();
            if (updateProperties.Any())
            {
                foreach (var property in updateProperties)
                {
                    AddParam(cmd, property);
                    sbKeys.AppendFormat("\t{0} = @{1}, \r\n", property.ColumnName, counter++);
                }
                cmd.AddParams(entity.Key.Select(x => x.Value.Raw).ToArray());
                var keys = sbKeys.ToString().Substring(0, sbKeys.Length - 4);
                var whereParts = new List<string>();
                foreach (var key in entity.Key)
                {
                    whereParts.Add("{0} = @{1}".Fill(key.ColumnName, counter++));
                }
                var wherePart = string.Join(" AND ", whereParts);
                cmd.CommandText = SqlFormat.Fill(entity.TableName, keys, wherePart);
            }
            cmd.AddParam(entity.JoinedKeyValue);
            cmd.CommandText += SqlReturnRecordIdPart.Fill(counter);

            return cmd;
        }
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:31,代码来源:RecordsUpdater.cs

示例4: GetEntityHierarchy

        private EntityHierarchy GetEntityHierarchy(
            EntityHierarchy parent,
            Entity entity,
            ref int index)
        {
            var hierarchy = new EntityHierarchy
            {
                Entity = entity,
                Alias = "[t" + index + "]",
                SubHierarchies = new List<EntityHierarchy>(),
                ParentHierarchy = parent
            };

            foreach (var property in entity.CreateProperties()
                .Where(x => x.IsForeignKey && x.TypeInfo.IsCollection)
                .Where(property =>
                    parent == null ||
                    parent.Entity != property.ForeignEntity))
            {
                index++;
                var subHierarchy =
                    GetEntityHierarchy(hierarchy, property.ForeignEntity, ref index);
                hierarchy.SubHierarchies.Add(subHierarchy);
            }

            return hierarchy;
        }
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:27,代码来源:RecordsHierarchySource.cs

示例5: PrepareGroups

        public IList<GroupProperties> PrepareGroups(Entity entity, bool getKey = true, string key = null)
        {
            var properties = entity.CreateProperties(getKey);
            foreach (var foreign in properties.Where(x => x.IsForeignKey))
            {
                var records = _source.GetRecords(foreign.ForeignEntity, determineDisplayValue: true).Records;
                foreign.Value.PossibleValues = records.ToDictionary(x => x.JoinedKeyValue, x => x.DisplayName);
                if (foreign.TypeInfo.IsCollection)
                {
                    foreign.Value.Values = records
                        .Where(x => x.Values.Any(y => y.Property.ForeignEntity == entity && y.AsString == key))
                        .Select(x => x.JoinedKeyValue)
                        .OfType<object>()
                        .ToList();
                }
            }

            return entity.Groups;
        }
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:19,代码来源:EntityService.cs

示例6: Delete

        public bool Delete(Entity entity, string key, IEnumerable<PropertyDeleteOption> options)
        {
            var existingRecord = _source.GetRecord(entity, key);
            if (existingRecord == null)
            {
                _notificator.Error(IlaroAdminResources.EntityNotExist);
                return false;
            }
            entity.SetKeyValue(key);

            options = options ?? new List<PropertyDeleteOption>();
            var deleteOptions = options.ToDictionary(x => x.PropertyName, x => x.DeleteOption);
            foreach (var property in entity.GetForeignsForUpdate())
            {
                if (!deleteOptions.ContainsKey(property.ForeignEntity.Name))
                {
                    deleteOptions[property.ForeignEntity.Name] = property.DeleteOption;
                }
            }

            var result = _deleter.Delete(entity, deleteOptions, () => _changeDescriber.DeleteChanges(entity, existingRecord));

            if (result)
            {
                var propertiesWithFilesToDelete = entity
                    .CreateProperties(getForeignCollection: false)
                    .Where(x => x.TypeInfo.IsFile && x.TypeInfo.IsFileStoredInDb == false);
                _filesHandler.Delete(propertiesWithFilesToDelete);
            }

            return result;
        }
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:32,代码来源:EntityService.cs

示例7: CreateBaseCommand

        protected virtual DbCommand CreateBaseCommand(Entity entity)
        {
            var sbKeys = new StringBuilder();

            var cmd = DB.CreateCommand();
            var counter = 0;
            foreach (var property in
                entity.CreateProperties(getForeignCollection: false).Where(x => x.IsKey == false))
            {
                AddParam(cmd, property);
                sbKeys.AppendFormat("\t{0} = @{1}, \r\n", property.ColumnName, counter);
                counter++;
            }
            cmd.AddParam(entity.Key.Value.Raw);
            var keys = sbKeys.ToString().Substring(0, sbKeys.Length - 4);
            cmd.CommandText = SqlFormat.Fill(entity.TableName, keys, entity.Key.ColumnName, counter);

            return cmd;
        }
开发者ID:Anupam-,项目名称:Ilaro.Admin,代码行数:19,代码来源:RecordsUpdater.cs

示例8: Upload

        /// <summary>
        /// Upload files to temp location, or save file byte array to property value
        /// </summary>
        public IList<Property> Upload(Entity entity)
        {
            var proccessedProperties = new List<Property>();
            foreach (var property in entity
                .CreateProperties(getForeignCollection: false)
                .Where(x => x.TypeInfo.IsFile))
            {
                if (property.Value.Raw.IsBehavior(DataBehavior.Clear))
                {
                    property.Value.Raw = property.Value.DefaultValue;
                    proccessedProperties.Add(property);
                    continue;
                }
                var file = (HttpPostedFileWrapper)property.Value.Raw;
                if (file == null || file.ContentLength == 0)
                {
                    property.Value.Raw = DataBehavior.Skip;
                    continue;
                }

                if (property.TypeInfo.IsFileStoredInDb)
                {
                    var setting = property.FileOptions.Settings.FirstOrDefault();
                    var fileInputStream = property.TypeInfo.IsImage ?
                        _resizer.Resize(file.InputStream, setting.Width, setting.Height) :
                        file.InputStream;

                    var bytes = _saver.GetFileByteArray(fileInputStream);
                    property.Value.Raw = bytes;
                }
                else
                {
                    var fileName = _fileNameCreator.GetFileName(property, file);
                    property.Value.Raw = fileName;

                    if (property.TypeInfo.IsImage)
                    {
                        foreach (var setting in property.FileOptions.Settings)
                        {
                            var resizedStream = _resizer.Resize(
                                file.InputStream,
                                setting.Width,
                                setting.Height);

                            var subPath =
                                setting.SubPath.TrimEnd('/', '\\') +
                                _configuration.UploadFilesTempFolderSufix;
                            var path = Path.Combine(BasePath, property.FileOptions.Path, subPath, fileName);

                            _saver.SaveFile(resizedStream, path);
                            resizedStream.Dispose();
                        }
                    }
                    else
                    {
                        var subPath =
                            property.FileOptions.Path.TrimEnd('/', '\\') +
                            _configuration.UploadFilesTempFolderSufix;
                        var path = Path.Combine(BasePath, subPath, fileName);

                        _saver.SaveFile(file.InputStream, path);
                    }

                    proccessedProperties.Add(property);
                }

                file.InputStream.Dispose();
            }

            return proccessedProperties;
        }
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:74,代码来源:FileHandler.cs


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