Hỏi đáp
Chia sẻ kiến thức, cùng nhau phát triển
Hỏi về lỗi entity framework khi làm đồ án khóa luận
Chào anh Long, em đang làm 1 đồ án khóa luận về phần mềm quản lý quán cà phê sử dụng mô hình MVVM, sử dụng Emtity Framework để kết nối CSDL, đến ngay chỗ thanh toán hóa đơn, em có làm như thế này:
Trong ViewModel em tạo 1 class có tên là BillViewModel.cs, trong đó em có tạo 1 hàm CheckOut:
BillViewModel.cs:
public bool CheckOut(int id)
{
var checkOut=DataProvider.Instance.Data.Database.SqlQuery<Bill>("UPDATE Bill SET status = 1 WHERE Id = " + id);
if(checkOut.Count()>0)
{
return true;
}
return false;
}
Qua bên giao diện khi nhấn nút thanh toán thì:
Code khi click nút thanh toán:
private void btnCheckOut_Click(object sender, RoutedEventArgs e)
{
TableFood table = lsvBill.Tag as TableFood;
int BillID = BillViewMdoel.Instance.GetUncheckBillIDByTableID(table.Id);
if (BillID != -1)
{
if (MessageBox.Show("Bạn có muốn thanh toán hóa đơn cho bàn " + table.Name, "Thông báo", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
BillViewMdoel.Instance.CheckOut(BillID);
ShowBill(table.Id);
}
}
}
Khi em chay lên thì báo lỗi như thế này:
The data reader is incompatible with the specified 'CofeeShopMangementModel.Bill'. A member of the type, 'Id', does not have a corresponding column in the data reader with the same name
Em có tìm hiểu trên mạng chỉ nói lỗi này xảy ra khi dùng store procedure nên em không fix được, anh có thể giúp em được không? Em cảm ơn anh