/**/////////////////////////////////////////
//Author: www.anytao.com //
//Date: 2007-4-5 //
//To Guanwei, a simple ORM example. //
/**/////////////////////////////////////////
using System;
namespace Anytao.Data
{
public class Student
{
//定义属性和数据库中表Student一一对应
private string _name;
public string Name
{
get {return _name;}
set {_name = value;}
}
private int _age;
public int Age
{
get {return _age;}
set {_age = value;}
}
void Student(IDataAccessProvider dap)
{
dap.GetStudent(this);
}
}
interface IDataAccessProvider
{
//再次可以声明要实现的所有业务逻辑
public void GetStudent(Student s);
public void SetStudent(Student s);
}
public class SqlDataAccessProvider: IDataAccessProvider
{
public void GetStudent(Student s)
{
SqlConnection conn = new SqlConnection("DataSource = .; Catalog = ");
SqlCommand com = new SqlCommand("Select name, age from Student", conn);
com.Open();
SqlDataReader reader = com.ExecuteNonQuery();
while(reader.Read())
{
Console.WriteLine("The age of student {0} is {1} .", reader[0], reader[1]);
}
}
public void SaveStudent(Student s)
{
//
}
}
public class OracleAccessProvider: IDataAccessProvider
{
public void GetStudent(Student s)
{
//
}
public void SaveStudent(Student s)
{
//
}
}
}