0

我一直在努力ObjectQuery,但后来我发现它只用于早期版本的 Visual Studio。我不知道在 Visual Studio 2017 中使用什么以及如何使用它。有人可以帮忙吗?如您所见,我正在使用实体框架。我已经阅读了一些关于查询的内容,但我不知道是否可以使用其他内容。

    namespace POSsytemFlamenca
    {
        public partial class LaFlamencaPSO : Form
        {
            private BindingList<TblProduct> products = new BindingList<TblProduct>();
            private FlamencaProEntities1 cse = new FlamencaProEntities1();

            public LaFlamencaPSO()
            {
                InitializeComponent();
                listProductChosen.DataSource = products;
                listProductChosen.DisplayMember = "Description";
                CreateTabbedPanel();
                AddProductsToTabbedPanel();

            }

            private void AddProductsToTabbedPanel()
            {
                int i = 1;

                foreach (TabPage tp in tabControl1.TabPages)
                { 
                    // this is the problem
                    ObjectQuery<TblProduct> filteredproduct = new ObjectQuery<TblProduct>("SELECT VALUE P FROM TblProducts AS P WHERE P.ProductType = " + i.ToString(), cse);

                    FlowLayoutPanel flp = new FlowLayoutPanel();
                    flp.Dock = DockStyle.Fill;

                    foreach (TblProduct tprod in filteredproduct)
                    {
                        Button b = new Button();
                        b.Size = new Size(100, 100);
                        b.Text = tprod.Description;
                        flp.Controls.Add(b);
                    }

                    tp.Controls.Add(flp);
                    i++;
                }
            }

            private void CreateTabbedPanel()
            {
                foreach (TblProductType pt in cse.TblProductTypes)
                {
                    tabControl1.TabPages.Add(pt.ProductType.ToString(), pt.Description);
                }
            }

            private void button1_Click(object sender, EventArgs e)
            {
                TblProduct p = new TblProduct() { Description = "Product A", 
                Price = 1.99M };
                products.Add(p);
            }

            private void FormtListItem(object sender, ListControlConvertEventArgs e)
            {
                string currentDescription = ((TblProduct)e.ListItem).Description;
                string currentPrice = string.Format("{0:C}",((TblProduct)e.ListItem).Price);
                string curretDescriptionPadded = currentDescription.PadRight(30);

                e.Value = curretDescriptionPadded + currentPrice;
            }
        }
    }
4

1 回答 1

0

您可以尝试 Linq 的基本方法:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/basic-linq-query-operations

或者

https://msdn.microsoft.com/en-us/library/gg509017.aspx

于 2018-01-22T21:20:40.940 回答