Ai giúp mình giải quyết Exception này với mình làm mô hình 3 lớp
Additional information: The type initializer for ‘DAO.ProductDAO’ threw an exception.
Exception trong C#: Additional information: The type initializer for 'DAO.ProductDAO' threw an exception
bạn up code lớp ProductDAO lên để mọi người xem rõ hơn
1 Like
Lớp DTO :
namespace DTO
{
public class ProductDTO
{
public int ProductID { set; get; }
public string ProductName { set; get; }
public string Description { set; get; }
public int CategoryID { set; get; }
}
}
Lớp DAO :
namespace DAO
{
public class ProductDAO
{
static Sample3Entities se = new Sample3Entities();
public static List<ProductDTO> GetList() {
return (se.Products.Select(item => new ProductDTO {
ProductID=item.ProductID,
ProductName=item.ProductName,
Description=item.Description,
CategoryID=item.CategoryID
})).ToList();
}
}
}
LỚP BUS :
namespace BUS
{
public class ProductBUS
{
public static List<ProductDTO> GetList() {
return ProductDAO.GetList();
}
}
}
GUI :
namespace GUI {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
dataGridView1.DataSource = BUS.ProductBUS.GetList();
}
}
}
GIúp mình với
nếu không nhầm thì bạn chưa khởi tạo class ProductDAO. bạn thử chỉnh lại class ProductBUS như code bên dưới xem sao.
public class ProductBUS
{
var productDAO = new ProductDAO();
public static List<ProductDTO> GetList()
{
return productDAO.GetList();
}
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?