在当前范围或上下文中无法解决.确保所有引用的变量都在范围内 [英] Could not be resolved in the current scope or context. Make sure that all referenced variables are in scope

查看:53
本文介绍了在当前范围或上下文中无法解决.确保所有引用的变量都在范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:在当前范围或上下文中无法解析'TblProduct'.请确保所有引用的变量都在范围内,已加载所需的模式,并且正确地引用了名称空间."在下面的代码中,我不确定为什么它不能正常工作.我希望有人可以提供帮助,谢谢!:

I get this error: "'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." In the following code, and I am not sure why it is not working correctly. I was hoping someone might be able to help, Thanks!:

    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(), pse);

            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;

                b.Tag = tprod;

                b.Click += new EventHandler(UpdateProductList);

                tp.Controls.Add(b);
            }

推荐答案

您需要在上下文中将TblProduct指定为DbSet..根据您提供的信息,我想这就是您错过的内容.会是这样的.

You need to specify your TblProduct as a DbSet in your context.. from the information you have provided I guess that is what you have missed. It would be something like this..

public class ProductContext : DbContext
{
    public DbSet<Category> TblCategories { get; set; }
    public DbSet<Product> TblProduct { get; set; }
}

这篇关于在当前范围或上下文中无法解决.确保所有引用的变量都在范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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