Ejemplo n.º 1
0
        private string BuildSqlSelect(Type type, string whereString)
        {
            ObjectDescription od     = new ObjectDescription(type, _ps);
            string            select = "SELECT ";

            foreach (PropertyDescription property in od.MappedProperties)
            {
                //if ( property.IsRelation || property.IsNonPersistent || property.IsInternal )
                //    continue;
                if (select != "SELECT ")
                {
                    select += ", ";
                }
                select += Mapper[property.Name, true];
            }
            select += " FROM ";
            select += Mapper.FullTableName;

            string where = " WHERE ";
            TableAttribute attr = od.DbTableAttribute;

            if (attr != null && attr.ToString() != "")
            {
                where += "( " + attr.ToString() + " )";
            }
            if (whereString != "")
            {
                if (attr != null && attr.ToString() != "")
                {
                    where += " AND ( " + whereString + " )";
                }
                else
                {
                    where += whereString;
                }
            }
            if (where.Trim() != "WHERE")
            {
                select += where;
            }

            return(select);
        }
Ejemplo n.º 2
0
        private string BuildGetMTMQuery(PropertyDescription property, object entityId)
        {
            Cryptany.Core.DPO.Mapper m = new Mapper(property.ReflectedObject.ObjectType, _ps);
            string mtmTableName        = "";

            if (!string.IsNullOrEmpty(property.RelationAttribute.SchemaName))
            {
                mtmTableName = property.RelationAttribute.SchemaName + "."
                               + property.RelationAttribute.MamyToManyRelationTable;
            }
            else if (m.SchemaName != "")
            {
                mtmTableName = m.SchemaName + "." + property.RelationAttribute.MamyToManyRelationTable;
            }
            else
            {
                mtmTableName = property.RelationAttribute.MamyToManyRelationTable;
            }
            string select = "SELECT t1.";

            select += property.RelationAttribute.MtmRelationTableParentColumn + ", ";
            select += property.RelationAttribute.MtmRelationTableChildColumn + " ";
            select += "FROM " + mtmTableName + " AS t1 ";

            ObjectDescription od   = ClassFactory.GetObjectDescription(ReflectedType, _ps);
            TableAttribute    attr = od.DbTableAttribute;

            if (attr != null && attr.ToString() != "")
            {
                string select2 = "INNER JOIN " + Mapper.FullTableName + " AS t2 ON ";
                select2 += "t1." + property.RelationAttribute.MtmRelationTableParentColumn + " = ";
                select2 += "t2." + Mapper[od.IdField.Name, true];
                select2 += " AND t2." + attr.ToString();
                select  += select2;
            }
            if (entityId != null)
            {
                string where = " WHERE t1." + m[od.IdField.Name, true] + " = " + IdToString(entityId);
                select      += where;
            }
            return(select);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine("Your model assembly name:");
            var assemblyName = Console.ReadLine();

            var asm     = Assembly.Load(assemblyName);
            var classes = asm.GetTypes().Where(p => p.IsClass).ToList();

            foreach (var item in classes)
            {
                                // Just grabbing this to get hold of the type name:
                                var type = item.GetType();

                                // Get the PropertyInfo object:
                                var properties = item.GetProperties();

                if (HasEFDataAnnotaion(properties))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Found Data Annotations attributes at {0} ...", item.FullName);
                    foreach (var property in properties)
                    {
                        var attributes = property.GetCustomAttributes(false);

                        // Using reflection.
                        Attribute[] attrs = System.Attribute.GetCustomAttributes(property);

                        // Displaying output.
                        foreach (Attribute attr in attrs)
                        {
                            if (attr is KeyAttribute)
                            {
                                KeyAttribute a = (KeyAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ForeignKeyAttribute)
                            {
                                ForeignKeyAttribute a = (ForeignKeyAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is IndexAttribute)
                            {
                                IndexAttribute a = (IndexAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.GetType().FullName + a.ToString(), property.Name);
                            }

                            if (attr is RequiredAttribute)
                            {
                                RequiredAttribute a = (RequiredAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is TimestampAttribute)
                            {
                                TimestampAttribute a = (TimestampAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ConcurrencyCheckAttribute)
                            {
                                ConcurrencyCheckAttribute a = (ConcurrencyCheckAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is MinLengthAttribute)
                            {
                                MinLengthAttribute a = (MinLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is MaxLengthAttribute)
                            {
                                MaxLengthAttribute a = (MaxLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is StringLengthAttribute)
                            {
                                StringLengthAttribute a = (StringLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is TableAttribute)
                            {
                                TableAttribute a = (TableAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ColumnAttribute)
                            {
                                ColumnAttribute a = (ColumnAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is DatabaseGeneratedAttribute)
                            {
                                DatabaseGeneratedAttribute a = (DatabaseGeneratedAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ComplexTypeAttribute)
                            {
                                ComplexTypeAttribute a = (ComplexTypeAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }
                        }
                    }
                }
            }
        }