【问题标题】:ObjectQuery<T> does not work in Entity Framework! Any suggestion what to use insted ofObjectQuery<T> 在实体框架中不起作用!任何建议使用什么
【发布时间】:2018-07-01 14:14:39
【问题描述】:

我一直在努力使用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;
            }
        }
    }

【问题讨论】:

    标签: c# entity-framework visual-studio-2017 linq-to-entities objectquery


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2017-05-09
    相关资源
    最近更新 更多