月度归档: 2014 年 12 月

  • centos安装LAMP记录

    centos安装LAMP记录

    wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.10.tar.gz
    wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.1.tar.gz
    wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
    tar -xvf httpd-2.4.10.tar.gz
    tar -xvf apr-1.5.1.tar.gz
    tar -xvf apr-util-1.5.4.tar.gz
    mv apr-1.5.1 httpd-2.4.10/srclib/apr
    mv apr-util-1.5.4 httpd-2.4.10/srclib/apr-util
    cd httpd-2.4.10
    yum -y install pcre-devel.x86_64
    ./configure  --prefix=/web/httpd --with-included-apr --enable-nonportable-atomics=yes --with-z
    make
    make install
    cp /web/httpd/bin/apachectl /etc/init.d/httpd
    vi /etc/init.d/httpd
    #!/bin/sh下加上
    # chkconfig: 35 85 15
    # description: Activates/Deactivates Apache 2.4.10
    chkconfig --add httpd
    chkconfig httpd on

    以下是配置httpd
    vi /web/httpd/conf/httpd.conf
    修改 ServerName 为 127.0.0.1:80

    ———————————————- 以下是PHP

    http://cn2.php.net/distributions/php-5.6.4.tar.bz2
    tar -xvf  php-5.6.4.tar.bz2
    cd php-5.6.4
    yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel
    ./configure --prefix=/web/php --with-apxs2=/web/httpd/bin/apxs --enable-cli --enable-shared --with-libxml-dir --with-gd --with-openssl --enable-mbstring --with-mcrypt --with-mysqli --with-mysql --enable-opcache --enable-mysqlnd --enable-zip --with-zlib-dir --with-pdo-mysql --with-jpeg-dir --with-freetype-dir --with-curl --without-pdo-sqlite --without-sqlite3
    make
    make install
    cp php.ini-development /web/php/lib/php.ini

    vim /web/php/lib/php.ini
    查找 date.timezone,修改为Asia/Shanghai

    vim /web/httpd/conf/httpd.conf
    查找 AddType application/x-gzip .gz .tgz
    在下一行添加:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps


    查找DirectoryIndex index.html
    在下一行添加
    index.php

    最后是修改httpd.conf的httpdocs目录,以及支持.htaccess。就不写了。

    —————————————————–以下是MYSQL
    安装yum install mysql mysql-server


    启动 service mysqld start


    配置 /usr/bin/mysql_secure_installation


    开机启动 chkconfig mysqld on


    登录数据库

    mysql -p

    开启root远程访问

    grant all privileges on *.* to 'root'@'%' identified by 'xinyangwu' with grant option;
    
    FLUSH PRIVILEGES;
  • VS2013根据JSON生成类

    VS2013根据JSON生成类

    VS自带功能:

    VS2013 : Edit -> Paste Special -> Paste JSON As Classes

    VS2012 : Install [ASP.NET and Web Tools] 

    在线工具:

    http://json2csharp.com/

  • SQL SERVER更改字段名

    SQL SERVER更改字段名

    --把Account表的Pwd字段改名为Pwd2
    exec sp_rename 'Account.[Pwd]' ,'Pwd2'

  • SQL SERVER 生成数据库表对应的实体类的存储过程

    SQL SERVER 生成数据库表对应的实体类的存储过程

    CREATE PROCEDURE [dbo].[CreateModel]   
        @tableName varchar(100 )
    AS
    BEGIN
    SET NOCOUNT ON;
    
    -- Subquery to return only the copy paste text
    Select PropertyColumn from (
        SELECT 1 as rowNr, 'public class ' + @tableName + ' {' as PropertyColumn
        UNION
        SELECT 2 as rowNr, 'public ' + a1. NewType + ' ' + a1.COLUMN_NAME + ' {get;set;}' as PropertyColumn
        -- ,* comment added so that i get copy pasteable output
         FROM
        (
            /*using top because i'm putting an order by ordinal_position on it.
            putting a top on it is the only way for a subquery to be ordered*/
            SELECT TOP 100 PERCENT
            COLUMN_NAME ,
            DATA_TYPE ,
            IS_NULLABLE ,
            CASE
                WHEN DATA_TYPE = 'varchar' THEN 'string'
                WHEN DATA_TYPE = 'nvarchar' THEN 'string'
                WHEN DATA_TYPE = 'datetime' AND IS_NULLABLE = 'NO' THEN 'DateTime'
                WHEN DATA_TYPE = 'datetime' AND IS_NULLABLE = 'YES' THEN 'DateTime?'
                WHEN DATA_TYPE = 'smalldatetime' AND IS_NULLABLE = 'NO' THEN 'DateTime'
                WHEN DATA_TYPE = 'datetime2' AND IS_NULLABLE = 'NO' THEN 'DateTime'
                WHEN DATA_TYPE = 'smalldatetime' AND IS_NULLABLE = 'YES' THEN 'DateTime?'
                WHEN DATA_TYPE = 'datetime2' AND IS_NULLABLE = 'YES' THEN 'DateTime?'
                WHEN DATA_TYPE = 'int' AND IS_NULLABLE = 'YES' THEN 'int?'
                WHEN DATA_TYPE = 'int' AND IS_NULLABLE = 'NO' THEN 'int'
                WHEN DATA_TYPE = 'smallint' AND IS_NULLABLE = 'NO' THEN 'Int16'
                WHEN DATA_TYPE = 'smallint' AND IS_NULLABLE = 'YES' THEN 'Int16?'
                WHEN DATA_TYPE = 'decimal' AND IS_NULLABLE = 'NO' THEN 'decimal'
                WHEN DATA_TYPE = 'decimal' AND IS_NULLABLE = 'YES' THEN 'decimal?'
                WHEN DATA_TYPE = 'numeric' AND IS_NULLABLE = 'NO' THEN 'decimal'
                WHEN DATA_TYPE = 'numeric' AND IS_NULLABLE = 'YES' THEN 'decimal?'
                WHEN DATA_TYPE = 'money' AND IS_NULLABLE = 'NO' THEN 'decimal'
                WHEN DATA_TYPE = 'money' AND IS_NULLABLE = 'YES' THEN 'decimal?'
                WHEN DATA_TYPE = 'bigint' AND IS_NULLABLE = 'NO' THEN 'long'
                WHEN DATA_TYPE = 'bigint' AND IS_NULLABLE = 'YES' THEN 'long?'
                WHEN DATA_TYPE = 'tinyint' AND IS_NULLABLE = 'NO' THEN 'byte'
                WHEN DATA_TYPE = 'tinyint' AND IS_NULLABLE = 'YES' THEN 'byte?'
                WHEN DATA_TYPE = 'char' THEN 'string'                       
                WHEN DATA_TYPE = 'timestamp' THEN 'byte[]'
                WHEN DATA_TYPE = 'varbinary' THEN 'byte[]'
                WHEN DATA_TYPE = 'bit' AND IS_NULLABLE = 'NO' THEN 'bool'
                WHEN DATA_TYPE = 'bit' AND IS_NULLABLE = 'YES' THEN 'bool?'
                WHEN DATA_TYPE = 'xml' THEN 'string'
            END AS NewType
            FROM INFORMATION_SCHEMA .COLUMNS
            WHERE TABLE_NAME = @tableName
            ORDER BY ORDINAL_POSITION
            ) AS a1
        UNION
        SELECT 3 as rowNr,   '} // class ' + @tableName
        ) as t Order By rowNr asc
    END
    
    --调用下面的代码生对指定表的实体类
    Helper_CreatePocoFromTableName 'Account'
    --调用下面的代码生成所有实体实
    USE Linshu
    GO
        DECLARE @field1 nvarchar(400 )
        DECLARE cur CURSOR LOCAL for
    
        SELECT TABLE_NAME FROM information_schema .tables
        OPEN cur
        FETCH NEXT FROM cur INTO @field1 --, @field2
        WHILE @@FETCH_STATUS = 0 BEGIN         
            exec Helper_CreatePocoFromTableName @field1 -- , @field2           
            fetch next from cur into @field1 -- , @field2
        END
    
    close cur
    deallocate cur
  • EF7的迁移还是挺简单的,在命令行中执行以下迁移命令

    EF7的迁移还是挺简单的,在命令行中执行以下迁移命令:

    k ef migration add initial
    k ef migration apply 

    说明,k就是早期的.net core。