problems with ObjectQuery<t> in Visual Studio 2013 .NE

本文关键字:Visual NE Studio in 2013 with ObjectQuery lt problems gt | 更新日期: 2023-09-27 18:10:12

我正在为一家医院的自助餐厅做POS我在youtube上看了一些如何用c#做POS的视频但我讲到这里他使用了ObjectQuery<T>类当我声明对象的实例时它给了我这个错误:

错误2参数2:不能从"Cafeteria_POS_EF4。BVH_POS_DB_MODEL_EF43"System.Data.Objects。ObjectContext的c: ' '托尼的' '视觉资料工作室2013'projects' cafia_pos_ef4 'cashregister.cs 46 119 cafia_pos_ef4

还有这个

错误1最佳重载方法匹配"System.Data.Objects.ObjectQuery.ObjectQuery(字符串,System.Data.Objects.ObjectContext)'有一些无效的参数c:'users'tony's'documents'visual studio2013'projects'咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅咖啡厅

我试着在互联网上搜索一些解决方案或其他东西,但我只找到旧教程,我不能理解微软说如何发送构造函数参数…我使用的是。net framework 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++;
        }
    }
}

}

problems with ObjectQuery<t> in Visual Studio 2013 .NE

我在论坛上找到了这个解决我问题的答案。

XXX的最佳重载方法匹配有一些无效参数

代码仍然不会运行,因为在foreach循环中发生了异常。

参数类型为POS_DB_MODEL。post_item_group '和'Edm。Int32'是不兼容的。在WHERE谓词第1行第58列附近