예제 #1
0
 public ColumnDef(ObjectDef objectDef, string name, string type, short length, bool isNullable, bool isPrimaryKey, ObjectDef referencedObject)
 {
     ObjectDef        = objectDef;
     Name             = name;
     Type             = type;
     Length           = length;
     IsNullable       = isNullable;
     IsPrimaryKey     = isPrimaryKey;
     ReferencedObject = referencedObject;
 }
예제 #2
0
        public void LoadDefinitions()
        {
            using (DataSet dataSet = _dataSource.GetDefinitions())
            {
                SchemaDefs = new List <SchemaDef>();
                ObjectDefs = new List <ObjectDef>();
                ColumnDefs = new List <ColumnDef>();

                foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                {
                    SchemaDef schemaDef = new SchemaDef(
                        dataRow.Field <int>("SchemaId"),
                        dataRow.Field <string>("Name"));

                    SchemaDefs.Add(schemaDef);
                }

                foreach (DataRow dataRow in dataSet.Tables[1].Rows)
                {
                    ObjectDef objectDef = new ObjectDef(
                        dataRow.Field <int>("ObjectId"),
                        SchemaDefs.Single(item => item.SchemaId == dataRow.Field <int>("SchemaId")),
                        dataRow.Field <string>("Name"));

                    ObjectDefs.Add(objectDef);
                }

                foreach (DataRow dataRow in dataSet.Tables[2].Rows)
                {
                    ObjectDef objectDef           = ObjectDefs.Single(item => item.TableId == dataRow.Field <int>("ObjectId"));
                    ObjectDef referencedObjectDef = dataRow.Field <int?>("ReferencedObjectId") == null ? null : ObjectDefs.Single(item => item.TableId == dataRow.Field <int?>("ReferencedObjectId"));

                    ColumnDef columnDef = new ColumnDef(
                        objectDef,
                        dataRow.Field <string>("Name"),
                        dataRow.Field <string>("Type"),
                        dataRow.Field <short>("Length"),
                        dataRow.Field <bool>("IsNullable"),
                        dataRow.Field <bool>("IsPrimaryKey"),
                        referencedObjectDef);

                    ColumnDefs.Add(columnDef);

                    if (dataRow.Field <bool>("IsPrimaryKey"))
                    {
                        objectDef.PrimayKeyColumn = columnDef;
                    }
                }
            }
        }
예제 #3
0
        internal SelectStatement(Builder builder, string @object, string alias, int pageSize, bool distinct, bool isPaged)
        {
            PageSize  = pageSize;
            Distinct  = distinct;
            IsPaged   = isPaged;
            PageIndex = 1;
            _builder  = builder;

            ObjectDef objectDef = builder.ObjectDefs.Single(item => item.FullName == @object);

            Join join = new Join(objectDef, alias);

            Joins         = new List <Join>(new[] { @join });
            SelectColumns = new List <SelectColumn>();
            WhereColumns  = new List <WhereColumn>();
        }
예제 #4
0
        public SelectStatement Join(string foreignKeyColumn, string alias)
        {
            /*
             * usage: .CreateSelect("core.Product", "p").Join("p.ProductTypeId", "pt")
             *
             * joins the foreign key p.ProductTypeId to the referenced object on its primary key
             */
            GetJoinAndColumnDef(foreignKeyColumn, (parentJoin, parentColumnDef) =>
            {
                ObjectDef objectDef = parentColumnDef.ReferencedObject;
                ColumnDef columnDef = objectDef.PrimayKeyColumn;

                Join join = new Join(parentJoin, parentColumnDef, columnDef, alias);

                Joins.Add(join);
            });

            return(this);
        }
예제 #5
0
        public SelectStatement Join(string parentAlias, string primaryObject, string alias)
        {
            /*
             * usage: .CreateSelect("core.ProductType", "pt").Join("pt", "core.Product", "p")
             *
             * joins the primary key of pt.ProductTypeId to the foreigh key of core.Product that references core.ProductType
             */
            Join parentJoin = Joins.Single(item => item.Alias == parentAlias);

            ObjectDef objectDef = _builder.ObjectDefs.Single(item => item.FullName == primaryObject);

            ColumnDef columnDef = _builder.ColumnDefs.Single(item => item.ObjectDef == objectDef && item.ReferencedObject == parentJoin.ObjectDef);

            Join join = new Join(parentJoin, parentJoin.ObjectDef.PrimayKeyColumn, columnDef, alias);

            Joins.Add(join);

            return(this);
        }