Rumah > pangkalan data > tutorial mysql > EntLib5.0 DAAB(Data Access Application Block),数据访问程序块

EntLib5.0 DAAB(Data Access Application Block),数据访问程序块

WBOY
Lepaskan: 2016-06-07 15:44:05
asal
1484 orang telah melayarinya

企业库下载:(还有相关视频及帮助文档) http://entlib.codeplex.com/ Entlib5.0 要求.net framework3.5 sp1,或 .net framework 4.0 App.config: ?xml version="1.0" encoding="utf-8" ?configuration configdivs div name="dataConfiguration" type="Micro

企业库下载:(还有相关视频及帮助文档)

http://entlib.codeplex.com/

Entlib5.0 要求.net framework3.5 sp1,或 .net framework 4.0

App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configdivs>
        <div name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirepermission="true"></div>
    </configdivs>
    <dataconfiguration defaultdatabase="DbConnString"></dataconfiguration>
    <connectionstrings>
        <add name="DbConnString" connectionstring="Data Source=myip;Initial Catalog=Test;User Id=sa;Password=MyPwd;" providername="System.Data.SqlClient"></add>
      <add name="DbConnString182" connectionstring="Data Source=myAnotherIP;Initial Catalog=DbName;User Id=User;Password=MyPwd" providername="System.Data.SqlClient"></add>
    </connectionstrings>
</configuration>
Salin selepas log masuk

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using System.Data;

namespace TestEntLib5_0InFramework3_5
{
    class Program
    {
        static void Main(string[] args)
        {
            Database db = DatabaseFactory.CreateDatabase();         //创建一个默认的数据库对象

            //Database db = DatabaseFactory.CreateDatabase("DbConnString182");      //创建一个命名的数据库对象

            //1.ExecuteNonQuery
            /*
            DbCommand dbCmd = db.GetSqlStringCommand(
                @"INSERT INTO T_EntLib (name,birthday,email) VALUES(N'吴1','2008-12-23','a@qq.com');
                INSERT INTO T_EntLib (name,birthday,email) VALUES(N'吴2','2008-12-23','gga@qq.com');
                INSERT INTO T_EntLib (name,birthday,email) VALUES(N'吴3','2008-12-23','a@qq.com');
                INSERT INTO T_EntLib (name,birthday,email) VALUES(N'吴4','2008-12-23','a@qq.com');
                INSERT INTO T_EntLib (name,birthday,email) VALUES(N'吴5','2008-12-23','a@qq.com');");
            int iAffectedNum = db.ExecuteNonQuery(dbCmd);           //返回影响的条数
            Console.WriteLine(iAffectedNum);
            */

            //2. ExecuteDataSet自动开启关闭Connection 

            //var sql = "SELECT TOP 10 * FROM sys_draw ORDER BY id DESC";
            /*
            var sql = "SELECT * FROM T_EntLib";

            DbCommand cmd = db.GetSqlStringCommand(sql);

            //  No need to open the connection; just make the call.
            //	执行时监视:cmd.Connection.State
            DataSet ds = db.ExecuteDataSet(cmd);
            //在此处发现:cmd.Connection.State	Closed	System.Data.ConnectionState
            //说明自动关闭连接
            Console.WriteLine(ds.Tables[0].Rows.Count);
            int col = ds.Tables[0].Columns.Count;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                for (int i = 0; i (sql);       //使用默认的RowMapper

            IRowMapper  rowMapper = MapBuilder<info>.MapAllProperties()
                               .MapByName(x => x.NAME)
                               .DoNotMap(x => x.Email)
                               .DoNotMap(x=>x.Birthday)
                               .Build();
            var result = db.ExecuteSqlStringAccessor<info>(sql, rowMapper);  //使用自定义的RowMapper

            foreach (var item in result)
            {
                Console.WriteLine("ID={0},Name:{1},Birthday:{2},Email:{3}", item.Id, item.NAME, item.Birthday, item.Email);
            }
            Console.ReadKey();
        }
    }
}
</info></info>
Salin selepas log masuk

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestEntLib5_0InFramework3_5
{
    public class Info
    {
        public int Id { get; set; }
        public string NAME { get; set; }
        public string Email { get; set; }
        public DateTime Birthday { get; set; }
    }
}
Salin selepas log masuk

  

CREATE TABLE T_EntLib
(
	ID bigint IDENTITY,
	NAME nvarchar(50),
	Birthday datetime,
	Email varchar(50)
)
Salin selepas log masuk

 http://files.cnblogs.com/wucg/TestEntLib5_0InFramework3_5.zip

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan