如何修复system.data.entity.core.entitysqlexception? [英] How to fix system.data.entity.core.entitysqlexception?

查看:103
本文介绍了如何修复system.data.entity.core.entitysqlexception?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void AddProductsToTabbedPanel()
{
    int i = 1;

    foreach (TabPage tp in tabControl1.TabPages) /*<---- (System.Data.Entity.Core.EntitySqlException occurred
HResult=0x8013193A
Message='tblProduct' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 1, column 21.)*/
    {
        ObjectQuery<tblproduct> filteredProduct = new ObjectQuery<tblproduct>("SELECT VALUE P FROM tblProduct AS P WHERE P.ProductType=" + i.ToString(), ((IObjectContextAdapter)pce).ObjectContext);

        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);
        }

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

void UpdateProductList(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tblProduct p = (tblProduct)b.Tag;
    products.Add(p);
    UpdateCustomerInformationPanel(p);

    TransactionTotal = TransactionTotal + (decimal)p.Price;

    lstProductChosen.SelectedIndex = lstProductChosen.Items.Count - 1;
}





我的尝试:



已将tblProduct添加到DBSet

公共虚拟DbSet< tblproduct> tblProducts {get;组; }

公共虚拟DbSet< tblproducttype> tblProductTypes {get;组; }

公共虚拟DbSet< tbltransaction> tblTransactions {get;组; }

公共虚拟DbSet< tbltransactionitem> tblTransactionItems {get;组; }



What I have tried:

already added the tblProduct to DBSet
public virtual DbSet<tblproduct> tblProducts { get; set; }
public virtual DbSet<tblproducttype> tblProductTypes { get; set; }
public virtual DbSet<tbltransaction> tblTransactions { get; set; }
public virtual DbSet<tbltransactionitem> tblTransactionItems { get; set; }

推荐答案

快速浏览一下,我发现你正在使用tblproduct和tblProduct。确保选项卡控件的数据绑定设置正确,因为C#区分大小写。
At quick glance I see you are using both tblproduct and tblProduct. Make sure that the data binding for your tab control is set correctly as C# is case sensitive.


这篇关于如何修复system.data.entity.core.entitysqlexception?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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