我正在为医院的自助餐厅做一个 POS,我正在 youtube 上观看一些关于如何在 c# 中做 POS 的视频,但我到了他使用ObjectQuery<T>
类的部分,以及当我声明它给出的对象的实例时我这个错误:
错误 2 参数 2:无法从 'Cafeteria_POS_EF4.BVH_POS_DB_MODEL_EF43' 转换为 'System.Data.Objects.ObjectContext' c:\users\tony's\documents\visual studio 2013\projects\cafeteria_pos_ef4\cafeteria_pos_ef4\cashregister.cs 46 119 Cafeteria_POS_EF4
和这个:
错误 1 'System.Data.Objects.ObjectQuery.ObjectQuery(string, System.Data.Objects.ObjectContext)' 的最佳重载方法匹配有一些无效参数 c:\users\tony's\documents\visual studio 2013\projects\cafeteria_pos_ef4 \cafeteria_pos_ef4\cashregister.cs 46 49 Cafeteria_POS_EF4
我尝试在互联网上搜索一些解决方案或其他东西,但我只找到旧教程,我无法理解微软所说的如何发送构造函数参数......我正在使用 .NET 框架 4 和 Visual Studio 2013。
PS - 我想使用ObjectQuery
,因为我想做一个foreach
循环来TabControl
动态填充数据库中的项目
ObjectQuery<pos_item> filteredProduct = new ObjectQuery<pos_item>("SELECT VALUE P FROM pos_item AS P WHERE P.pos_item_group = " + i.ToString(), cse);
如果你们想看全班我把它贴在下面提前感谢您的时间和精力
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Objects;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cafeteria_POS_EF4
{
public partial class CashRegister : Form
{
private BindingList<pos_item> products = new BindingList<pos_item>();
private BVH_POS_DB_MODEL_EF43 cse = new BVH_POS_DB_MODEL_EF43();
public CashRegister()
{
InitializeComponent();
lboxBasket.DataSource = products;
lboxBasket.DisplayMember = "description";
//pos_item p = new pos_item() { };
CreateTabbedPanel();
FillTabbedPanel();
}
private void CreateTabbedPanel()
{
foreach(pos_item_group ig in cse.pos_item_group)
{
tabControl.TabPages.Add(ig.item_group_id.ToString(), ig.item_group_name);
}
}
private void FillTabbedPanel()
{
int i = 1;
foreach(TabPage tp in tabControl.TabPages)
{
ObjectQuery<pos_item> filteredProduct = new ObjectQuery<pos_item>("SELECT VALUE P FROM pos_item AS P WHERE P.pos_item_group = " + i.ToString(), cse);
FlowLayoutPanel flp = new FlowLayoutPanel();
flp.Dock = DockStyle.Fill;
foreach (pos_item item in filteredProduct)
{
Button b = new Button();
b.Text = item.description;
tp.Controls.Add(b);
}
tp.Controls.Add(flp);
i++;
}
}
}
}