Inheritance: IImportDomain
Exemple #1
0
        public DataTable GetStaticData(string connectionString, Entity entity)
        {
            if (entity == null)
            {
                return(null);
            }
            var auditFields  = new List <SpecialField>();
            var importDomain = new ImportDomain();
            var dbEntity     = importDomain.Import(connectionString, auditFields).EntityList.FirstOrDefault(x => x.Name == entity.Name);

            if (dbEntity == null)
            {
                return(null);
            }

            //Get the columns that actually exist in the database
            var columnList = dbEntity.FieldList;

            var fieldList = entity.FieldList.Where(x => !x.IsBinaryType() && x.DataType != SqlDbType.Timestamp).ToList();

            //Load the static data grid
            var sb = new StringBuilder();

            sb.Append("SELECT ");
            foreach (var field in fieldList)
            {
                if (columnList.Count(x => x.Name.ToLower() == field.Name.ToLower()) == 1)
                {
                    //if (field.IsBinaryType()) sb.Append("NULL");
                    //else sb.Append("[" + field.Name + "]");
                    sb.Append("[" + field.Name + "]");
                }
                else
                {
                    sb.Append("'' AS [" + field.Name + "]");
                }
                if (fieldList.ToList().IndexOf(field) < fieldList.Count() - 1)
                {
                    sb.Append(",");
                }
            }
            sb.AppendLine(" FROM [" + entity.Name + "]");
            var ds = DatabaseHelper.ExecuteDataset(connectionString, sb.ToString());

            if (ds.Tables.Count == 0)
            {
                return(null);
            }
            return(ds.Tables[0]);
        }
Exemple #2
0
        public DataTable GetStaticData(string connectionString, Entity entity)
        {
            if (entity == null) return null;
            var auditFields = new List<SpecialField>();
            var importDomain = new ImportDomain();
            var dbEntity = importDomain.Import(connectionString, auditFields).EntityList.FirstOrDefault(x => x.Name == entity.Name);
            if (dbEntity == null) return null;

            //Get the columns that actually exist in the database
            var columnList = dbEntity.FieldList;

            var fieldList = entity.FieldList.Where(x => !x.IsBinaryType() && x.DataType != SqlDbType.Timestamp).ToList();

            //Load the static data grid
            var sb = new StringBuilder();
            sb.Append("SELECT ");
            foreach (var field in fieldList)
            {
                if (columnList.Count(x => x.Name.ToLower() == field.Name.ToLower()) == 1)
                {
                    //if (field.IsBinaryType()) sb.Append("NULL");
                    //else sb.Append("[" + field.Name + "]");
                    sb.Append("[" + field.Name + "]");
                }
                else
                {
                    sb.Append("'' AS [" + field.Name + "]");
                }
                if (fieldList.ToList().IndexOf(field) < fieldList.Count() - 1) sb.Append(",");
            }
            sb.AppendLine(" FROM [" + entity.Name + "]");
            var ds = DatabaseHelper.ExecuteDataset(connectionString, sb.ToString());

            if (ds.Tables.Count == 0) return null;
            return ds.Tables[0];
        }