【问题标题】:problems with ObjectQuery<t> in Visual Studio 2013 .NET Framework 4Visual Studio 2013 .NET Framework 4 中的 ObjectQuery<t> 问题
【发布时间】:2014-08-16 10:18:40
【问题描述】:

我正在为医院的自助餐厅做 POS,我正在 youtube 上观看一些关于如何在 c# 中做 POS 的视频,但我到了他使用 ObjectQuery&lt;T&gt; 类的部分,当我声明它给我这个错误的对象的实例:

错误 2 参数 2:无法从 'Cafeteria_POS_EF4.BVH_POS_DB_MODEL_EF43' 到 'System.Data.Objects.ObjectContext' c:\users\tony's\documents\visual 工作室 2013\projects\cafeteria_pos_ef4\cafeteria_pos_ef4\cashregister.cs 46 119 Cafeteria_POS_EF4

还有这个:

错误 1 ​​最好的重载方法匹配 'System.Data.Objects.ObjectQuery.ObjectQuery(字符串, 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

我尝试在互联网上搜索一些解决方案或其他东西,但我只找到旧教程,而且我无法理解 Microsoft 关于如何发送构造函数参数的说法......我正在使用 .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++;

        }

    }

}

}

【问题讨论】:

    标签: c# visual-studio-2013 objectquery


    【解决方案1】:

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

    The best overloaded method match for XXX has some invalid arguments

    由于foreach 循环中出现异常,代码仍然无法运行。

    参数类型“POS_DB_MODEL.pos_item_group”和“Edm.Int32”与此操作不兼容。在 WHERE 谓词附近,第 1 行,第 58 列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多