public static Select <TEntity> Select <TEntity>(string table = null, IDatabaseNamingConvention dbNamingConvention = null)
        {
            var type = typeof(TEntity);

            var query = new Select <TEntity>
            {
                NamingConvention = dbNamingConvention ?? DatabaseNamingConvention,
                From             = string.IsNullOrEmpty(table) ? type.Name : table
            };

            foreach (var property in type.GetProperties())
            {
                query.Columns.Add(property.Name);
            }

            return(query);
        }
Example #2
0
        public XsdOutputModel Convert(IDatabaseNamingConvention namingConvention, IProject project, INamespace ns,
                                      IEnumerable <Base.Models.Entity.Entity> entities)
        {
            _namingConvention = namingConvention;

            var rootXmlElement = new XElement(HbmNamespace + "mapping",
                                              new XAttribute("assembly", project.Name), // TODO: Use assembly name
                                              new XAttribute("namespace", ns.Name),
                                              new XAttribute("auto-import", "false")
                                              );

            foreach (var entity in entities)
            {
                rootXmlElement.Add(new XComment($"Generated from entity model '{ns.Name}'"));
                rootXmlElement.Add(Convert(entity));
            }

            return(new XsdOutputModel(rootXmlElement));
        }
Example #3
0
 /// <summary>
 /// Gets a database with default values (Default schema, support transactions, database type maps and naming convention)
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="defaultSchema">Default schema</param>
 /// <param name="databaseTypeMaps">Database type maps</param>
 /// <param name="namingConvention">Database naming convention</param>
 /// <returns>An instance of <see cref="Database"/> class</returns>
 public static SqlServerDatabase CreateWithDefaults(string name, string defaultSchema = "dbo", List <DatabaseTypeMap> databaseTypeMaps = null, IDatabaseNamingConvention namingConvention = null)
 => new SqlServerDatabase
 {
     Name                = name,
     DefaultSchema       = defaultSchema,
     SupportTransactions = true,
     DatabaseTypeMaps    = databaseTypeMaps ?? SqlServerDatabaseTypeMaps.DatabaseTypeMaps.ToList(),
     NamingConvention    = namingConvention ?? new SqlServerDatabaseNamingConvention()
 };
        public static DeleteFrom <TEntity> DeleteFrom <TEntity>(TEntity entity, string schema = null, string table = null, string key = null, IDatabaseNamingConvention dbNamingConvention = null)
        {
            var type = typeof(TEntity);

            var query = new DeleteFrom <TEntity>
            {
                NamingConvention = dbNamingConvention ?? DatabaseNamingConvention,
                Schema           = schema,
                Table            = string.IsNullOrEmpty(table) ? type.Name : table
            };

            var properties = type.GetProperties().ToList();

            if (properties.Any(item => item.Name == key))
            {
                query.Key = key;
            }

            query.Where.Add(new Condition(key, ComparisonOperator.Equals, type.GetProperty(key).GetValue(entity)));

            return(query);
        }
        public static Update <TEntity> Update <TEntity>(TEntity entity, string table = null, string key = null, IDatabaseNamingConvention dbNamingConvention = null)
        {
            var type = typeof(TEntity);

            var query = new Update <TEntity>
            {
                NamingConvention = dbNamingConvention ?? DatabaseNamingConvention,
                Table            = string.IsNullOrEmpty(table) ? type.Name : table
            };

            var properties = type.GetProperties().ToList();

            if (properties.Any(item => item.Name == key))
            {
                query.Key = key;
            }

            foreach (var property in properties)
            {
                if (!string.IsNullOrEmpty(key) && key == property.Name)
                {
                    continue;
                }

                var value = property.GetValue(entity);

                query.Columns.Add(new UpdateColumn(property.Name, value));
            }

            query.Where.Add(new Condition(key, ComparisonOperator.Equals, type.GetProperty(key).GetValue(entity)));

            return(query);
        }
        public static InsertInto <TEntity> InsertInto <TEntity>(TEntity entity, string table = null, string identity = null, IDatabaseNamingConvention dbNamingConvention = null)
        {
            var type = typeof(TEntity);

            var query = new InsertInto <TEntity>
            {
                NamingConvention = dbNamingConvention ?? DatabaseNamingConvention,
                Table            = string.IsNullOrEmpty(table) ? type.Name : table
            };

            var properties = type.GetProperties().ToList();

            if (properties.Any(item => item.Name == identity))
            {
                query.Identity = identity;
            }

            foreach (var property in properties)
            {
                if (!string.IsNullOrEmpty(identity) && identity == property.Name)
                {
                    continue;
                }

                var value = property.GetValue(entity);

                query.Columns.Add(new InsertIntoColumn(property.Name, value));
            }

            return(query);
        }
 static QueryBuilder()
 {
     DatabaseNamingConvention = new DatabaseNamingConvention();
 }
 static DbObjectExtensions()
 {
     namingConvention = new DatabaseNamingConvention();
 }