如何修复参数2:无法从实体'转换为'system.data.entity.core.objects.objectcontext [英] How do I fix argument 2: cannot convert from entities' to 'system.data.entity.core.objects.objectcontext

查看:104
本文介绍了如何修复参数2:无法从实体'转换为'system.data.entity.core.objects.objectcontext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void AddProductsToTabbedPanel()
        {
            int i = 1;

            foreach (TabPage tp in tabControl1.TabPages)
            {
                ObjectQuery<tblproduct> filteredProduct = new ObjectQuery<tblproduct>("SELECT VALUE P FROM tblProduct AS P WHERE P.ProductType=" + i.ToString(),pce);

                FlowLayoutPanel flp = new FlowLayoutPanel
                {
                    Dock = DockStyle.Fill
                };

                foreach (tblProduct tprod in filteredProduct)
                {
                    Button b = new Button
                    {
                        Size = new Size(100, 100),
                        Text = tprod.Description,
                        Tag = tprod
                    };
                    b.Click += new EventHandler(UpdateProductList);

                    tp.Controls.Add(b);
                    flp.Controls.Add(b);
                }



和这里


and here

private void FilterList(object sender, EventArgs e)
        {
            ObjectQuery<tblproduct> filteredProducts = new ObjectQuery<tblproduct>("SELECT VALUE product FROM tblProducts AS product WHERE product.ProductType = " + cboFilter.SelectedValue,pce);
            dataGridView1.DataSource = filteredProducts;
        }





我的尝试:



尝试将EF模型更新到最新版本,但该问题解决了问题



What I have tried:

tried to update EF model to latest version but that dosent fix the problem

推荐答案

您必须使用类型的正确对象。这是一个错字或更大的问题,pce不是正确的类型。



但是请确保您接下来是正确的对象上下文,因此请更正代码以提供查询的有效上下文。注意可能的SQL注入!!!
you must use a correct object of your type. Is it a typo or some bigger issue, that pce isnt of the right type.

But for sure you next a proper object context, so correct your code to provide a valid context for the query. Take care of the possible SQL injections!!!


这篇关于如何修复参数2:无法从实体'转换为'system.data.entity.core.objects.objectcontext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆