0

I'm doing a POS for a cafeteria in a hospital and I'm watching some videos in youtube of how to do the POS in c# but I got to this part where he uses ObjectQuery<T> class and when I declare the instance of the object it gives me this error:

Error 2 Argument 2: cannot convert from 'Cafeteria_POS_EF4.BVH_POS_DB_MODEL_EF43' to '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

And this one:

Error 1 The best overloaded method match for 'System.Data.Objects.ObjectQuery.ObjectQuery(string, System.Data.Objects.ObjectContext)' has some invalid arguments c:\users\tony's\documents\visual studio 2013\projects\cafeteria_pos_ef4\cafeteria_pos_ef4\cashregister.cs 46 49 Cafeteria_POS_EF4

I tried searching on the internet for some solution or something but I only find old tutorials and I cant understand what Microsoft says about how to send the constructor arguments... I'm using .NET framework 4 and Visual Studio 2013.

PS - I want to use ObjectQuery because i want to do a foreach loop to fill the TabControl Dynamically from the items in the database

 ObjectQuery<pos_item> filteredProduct = new ObjectQuery<pos_item>("SELECT VALUE P FROM pos_item AS P WHERE P.pos_item_group = " + i.ToString(), cse);

If you guys whant to see the whole class ima post it here below thanks in advance for your time and effort

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++;

        }

    }

}

}

Chris Barlow
  • 3,274
  • 4
  • 31
  • 52
Mali
  • 1
  • 1

1 Answers1

0

I found this answer here in forum that solved my problem.

The best overloaded method match for XXX has some invalid arguments

Still the code will not run because there is an exception ocurring in the foreach loop.

The argument types 'POS_DB_MODEL.pos_item_group' and 'Edm.Int32' are incompatible for this operation. Near WHERE predicate, line 1, column 58.

Community
  • 1
  • 1
Mali
  • 1
  • 1