透過Entity Framework取得資料庫資料。
namespace Project.Models
{
public class CustomerDAL
{
///
/// 取得本機驗證碼
///
///
public List<ustomer> GetAllCustomerData()
{
using (myDBEntities obj = new myDBEntities())
{
try
{
//使用linq語法來取得(篩選)資料
var query = (from c in obj.Customer
select c);
return query.ToList<Customer>();
}
catch (Exception ex)
{
return "";
}
}
}
}
}
Controller中的寫法:
public ActionResult Customers()
{
List<models.customer> customers = new CustomerDAL().GetAllCustomerData();
return View(customers);
}
沒有留言:
張貼留言