首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ObjectQuery无效参数

ObjectQuery无效参数
EN

Stack Overflow用户
提问于 2016-12-07 07:10:09
回答 1查看 39关注 0票数 0

我很难从db_Entities模型中过滤数据。我有一个绑定到comboBox1的表,并且我正在尝试使用comboBox1控件中的commitChanged事件筛选数据。我收到两个错误。1是:'System.Data.Entity.Core.Objects.ObjectQuery.ObjectQuery(string,System.Data.Entity.Core.Objects.ObjectContext)‘的最佳重载方法匹配包含一些无效参数。

第二个问题是:无法从'SmallStore.db_Entities‘转换为'System.Data.Entity.Core.Objects.ObjectContext'.为了节省空间,我省略了目录。以下是代码

代码语言:javascript
复制
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.Entity.Core.Objects;
    using System.Data.Entity.Core.Query;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;


    namespace SmallStore
    {
         public partial class ViewProducts : Form
         {                
           private db_Entities db = new db_Entities();

    public ViewProducts()
    {

        InitializeComponent();

        dataGridView1.DataSource = db.Products.ToList();

        dataGridView1.Columns["ProductType"].Visible = false;
        dataGridView1.Columns["TransactionItems"].Visible = false;
        dataGridView1.Columns["Product_Type"].Visible = false;

        comboBox1.DataSource = db.Product_Type.ToList();
        comboBox1.ValueMember = "Description";
        comboBox1.DisplayMember = "Product_Type";

    }

    private void changeCommit(object sender, EventArgs e)
    {
        /* filter products */
        ObjectQuery<Product> filteredProducts = new ObjectQuery<Product>("SELECT VALUE item FROM Products AS item WHERE item.ProductType = " + comboBox1.SelectedValue, db);

    }
}

}

EN

回答 1

Stack Overflow用户

发布于 2016-12-07 08:05:40

试试这个:

代码语言:javascript
复制
var querystring = "SELECT VALUE item FROM Products AS item WHERE item.ProductType = " + comboBox1.SelectedValue;  

Debugger.Break();  //Ensure querystring is what you want here

 var products = db.Database.SqlQuery<Product>(querystring).ToList();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41006632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档