最終實現後達到的效果,只需寫少量代碼就可實現CURD操作。
DAL層代碼:
StudentDAL代碼
public class StudentDAL
{
EntityManager entityManager = EntityManagerFactory.CreateEntityManager();
public StudentDAL() { }
public StudentDAL(IDbTransaction transaction)
{
entityManager.Transaction = transaction;
}
public List<StudentEntity> FindAll()
{
return entityManager.FindAll<StudentEntity> ();
}
public int Save(StudentEntity entity)
{
return entityManager.Save(entity);
}
public int Update(StudentEntity entity)
{
return entityManager.Update(entity);
}
public int Remove(StudentEntity entity)
{
return entityManager.Remove(entity);
}
public int Remove(object id)
{
return entityManager.Remove<StudentEntity> (id);
}
public List<StudentEntity> FindById(object id)
{
return entityManager.FindById<StudentEntity> (id);
}
public List<StudentEntity> FindByProperty(string propertyName,object value)
{
return entityManager.FindByProperty<StudentEntity>(propertyName, value);
}
}