public DatabaseFunction_EntityDTO ToDatabaseFunction_EntityDTO(DatabaseFunction_TableDrivedEntity cItem, bool withColumns)
        {
            BizColumn bizColumn = new BizColumn();
            var       result    = new DatabaseFunction_EntityDTO();

            result.ID                 = cItem.ID;
            result.Title              = cItem.Title;
            result.Name               = cItem.Name;
            result.EntityID           = cItem.TableDrivedEntityID;
            result.DatabaseFunctionID = cItem.DatabaseFunctionID;
            result.DatabaseFunction   = ToDatabaseFunctionDTO(cItem.DatabaseFunction, withColumns);
            if (withColumns)
            {
                result.DatabaseFunctionEntityColumns = ToDatabaseFunctionEntityColumnsDTO(cItem);
            }

            return(result);
        }
 public int UpdateDatabaseFunctionEntity(DatabaseFunction_EntityDTO DatabaseFunctionEntity)
 {
     using (var projectContext = new DataAccess.MyProjectEntities())
     {
         var dbDatabaseFunctionEntity = projectContext.DatabaseFunction_TableDrivedEntity.FirstOrDefault(x => x.ID == DatabaseFunctionEntity.ID);
         if (dbDatabaseFunctionEntity == null)
         {
             dbDatabaseFunctionEntity = new DatabaseFunction_TableDrivedEntity();
         }
         dbDatabaseFunctionEntity.DatabaseFunctionID  = DatabaseFunctionEntity.DatabaseFunctionID;
         dbDatabaseFunctionEntity.TableDrivedEntityID = DatabaseFunctionEntity.EntityID;
         dbDatabaseFunctionEntity.Title = DatabaseFunctionEntity.Title;
         dbDatabaseFunctionEntity.Name  = DatabaseFunctionEntity.Name;
         while (dbDatabaseFunctionEntity.DatabaseFunction_TableDrivedEntity_Columns.Any())
         {
             dbDatabaseFunctionEntity.DatabaseFunction_TableDrivedEntity_Columns.Remove(dbDatabaseFunctionEntity.DatabaseFunction_TableDrivedEntity_Columns.First());
         }
         foreach (var column in DatabaseFunctionEntity.DatabaseFunctionEntityColumns)
         {
             DatabaseFunction_TableDrivedEntity_Columns dbColumn = new DataAccess.DatabaseFunction_TableDrivedEntity_Columns();
             if (column.ColumnID != 0)
             {
                 dbColumn.ColumnID     = column.ColumnID;
                 dbColumn.FixedParamID = null;
             }
             else
             {
                 dbColumn.ColumnID     = null;
                 dbColumn.FixedParamID = (short)column.FixedParam;
             }
             dbColumn.DatabaseFunctionParameterID = column.DatabaseFunctionParameterID;
             dbDatabaseFunctionEntity.DatabaseFunction_TableDrivedEntity_Columns.Add(dbColumn);
         }
         if (dbDatabaseFunctionEntity.ID == 0)
         {
             projectContext.DatabaseFunction_TableDrivedEntity.Add(dbDatabaseFunctionEntity);
         }
         projectContext.SaveChanges();
         return(dbDatabaseFunctionEntity.ID);
     }
 }
        private List <DatabaseFunction_Entity_ColumnDTO> ToDatabaseFunctionEntityColumnsDTO(DatabaseFunction_TableDrivedEntity cItem)
        {
            BizColumn bizColumn = new BizColumn();
            List <DatabaseFunction_Entity_ColumnDTO> result = new List <DatabaseFunction_Entity_ColumnDTO>();

            foreach (var column in cItem.DatabaseFunction_TableDrivedEntity_Columns)
            {
                var item = new DatabaseFunction_Entity_ColumnDTO();
                item.ID = column.ID;
                item.DatabaseFunctionParameterID = column.DatabaseFunctionParameterID;
                item.DatabaseFunction_EntityID   = column.DatabaseFunction_TableDrivedEntityID;
                if (column.ColumnID != null)
                {
                    item.ColumnID   = column.ColumnID.Value;
                    item.ColumnName = column.Column.Name;
                }
                if (column.FixedParamID != null)
                {
                    item.FixedParam = (Enum_FixedParam)column.FixedParamID;
                }
                item.FunctionColumnDotNetType = bizColumn.GetColumnDotNetType(column.DatabaseFunctionParameter.DataType, false);
                item.FunctionColumnParamName  = column.DatabaseFunctionParameter.ParamName;
                result.Add(item);
            }
            return(result);
        }