예제 #1
0
        /*Create Parameter in Model*/
        public List <SqlParameter> CreateParameter(dynamic model)
        {
            List <dynamic> mod = new List <dynamic>();

            parameters = new List <SqlParameter>();
            param      = new SqlParameter();

            mod.Add(model);
            foreach (var KeyCol in mod)
            {
                foreach (var col in KeyCol.GetType().GetProperties())
                {
                    param = new SqlParameter();
                    param.ParameterName = col.Name;
                    if (!col.PropertyType.Name.Contains("List"))
                    {
                        if (col.GetValue(KeyCol) != null)
                        {
                            param.Value = col.GetValue(KeyCol).ToString();
                        }
                        parameters.Add(param);
                    }
                }
            }
            return(parameters);
        }
예제 #2
0
        public IMetadataRetrievable ImportSource(string psDatabaseTable, IModel poDbContext)
        {
            WonkaImportSource NewImportSource = new WonkaImportSource();
            HashSet <string>  KeyColNames     = new HashSet <string>();

            IEntityType FoundTable = null;

            if (!String.IsNullOrEmpty(psDatabaseTable) && (poDbContext != null))
            {
                if (moCachedImports.ContainsKey(psDatabaseTable))
                {
                    return(moCachedImports[psDatabaseTable]);
                }

                var tables = poDbContext.GetEntityTypes(psDatabaseTable);

                foreach (var TmpTable in tables)
                {
                    if (TmpTable.Name == psDatabaseTable)
                    {
                        FoundTable = TmpTable;

                        var KeyCols = TmpTable.GetDeclaredKeys();
                        foreach (var KeyCol in KeyCols)
                        {
                            KeyColNames.Add(KeyCol.GetName());
                        }

                        break;
                    }
                }

                if (FoundTable == null)
                {
                    throw new WonkaImportException("ERROR!  Table (" + psDatabaseTable + ") was not found in the provided DbContext.");
                }

                var columns =
                    from p in FoundTable.GetProperties()
                    select new
                {
                    colName   = p.Name,
                    colType   = p.GetColumnType(),
                    maxLength = p.GetMaxLength(),
                    precision = 0,
                    scale     = 0,
                    defValue  = p.GetDefaultValue()
                };

                /*
                 * var columns =
                 *  from meta in poDbContext.MetadataWorkspace.GetItems(DataSpace.CSpace).Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                 *  from p in (meta as EntityType).Properties.Where(p => p.DeclaringType.Name == psDatabaseTable)
                 *  select new
                 *  {
                 *      colName   = p.Name,
                 *      colType   = p.TypeUsage.EdmType,
                 *      doc       = p.Documentation,
                 *      maxLength = p.MaxLength,
                 *      precision = p.Precision,
                 *      scale     = p.Scale,
                 *      defValue  = p.DefaultValue,
                 *      props     = p.MetadataProperties
                 *  };
                 */

                foreach (var TmpCol in columns)
                {
                    string sTmpColName = TmpCol.colName;

                    WonkaRefAttr TmpWonkaAttr = new WonkaRefAttr();

                    TmpWonkaAttr.AttrId   = GenerateNewAttrId();
                    TmpWonkaAttr.AttrName = sTmpColName;
                    TmpWonkaAttr.ColName  = sTmpColName;
                    TmpWonkaAttr.TabName  = psDatabaseTable;

                    TmpWonkaAttr.DefaultValue = Convert.ToString(TmpCol.defValue);
                    // TmpWonkaAttr.Description  = (TmpCol.doc != null) ? TmpCol.doc.LongDescription : "";

                    TmpWonkaAttr.IsDate    = IsTypeDate(TmpCol.colType);
                    TmpWonkaAttr.IsNumeric = IsTypeNumeric(TmpCol.colType);
                    TmpWonkaAttr.IsDecimal = IsTypeDecimal(TmpCol.colType);

                    if (TmpWonkaAttr.IsNumeric || TmpWonkaAttr.IsDecimal)
                    {
                        // TmpWonkaAttr.Precision = (int) ((TmpCol.precision != null) ? TmpCol.precision : 0);
                        // TmpWonkaAttr.Scale     = (int) ((TmpCol.scale != null) ? TmpCol.scale : 0);
                        TmpWonkaAttr.Precision = TmpCol.precision;
                        TmpWonkaAttr.Scale     = TmpCol.scale;
                    }

                    TmpWonkaAttr.MaxLength = (TmpCol.maxLength != null) ? (int)TmpCol.maxLength : 0;

                    TmpWonkaAttr.FieldId   = TmpWonkaAttr.AttrId + 1000;
                    TmpWonkaAttr.GroupId   = CONST_DEFAULT_GROUP_ID;
                    TmpWonkaAttr.IsAudited = true;

                    TmpWonkaAttr.IsKey = KeyColNames.Contains(TmpWonkaAttr.AttrName);

                    NewImportSource.AddAttribute(TmpWonkaAttr);
                }

                if (NewImportSource.GetAttrCache().Count <= 0)
                {
                    throw new WonkaBizRuleException(0, 0, "ERROR!  Could not import the schema because the Reader's field count was zero.");
                }

                WonkaRefGroup NewImportGroup = new WonkaRefGroup();

                NewImportGroup.GroupId        = CONST_DEFAULT_GROUP_ID;
                NewImportGroup.GroupName      = psDatabaseTable;
                NewImportGroup.KeyTabCols     = KeyColNames;
                NewImportGroup.ProductTabName = psDatabaseTable;
                NewImportSource.AddGroup(NewImportGroup);

                WonkaRefSource GuestSource = new WonkaRefSource();

                GuestSource.SourceId   = 1;
                GuestSource.SourceName = "Guest";
                GuestSource.Status     = "Active";
                NewImportSource.AddSource(GuestSource);
            }
            else
            {
                throw new WonkaBizRuleException(0, 0, "ERROR!  Could not import the schema for the database table.");
            }

            PopulateDefaults();

            return(NewImportSource);
        }