0

i am having a hard time filtering data from a db_Entities model. I have a table bound to a comboBox1 and i am trying to filter data using the commitChanged event within the comboBox1 control. i am getting 2 errors. 1 is :The best overloaded method match for 'System.Data.Entity.Core.Objects.ObjectQuery.ObjectQuery(string, System.Data.Entity.Core.Objects.ObjectContext)' has some invalid arguments.
the 2nd one is: cannot convert from 'SmallStore.db_Entities' to 'System.Data.Entity.Core.Objects.ObjectContext'. i left the directory out to save space. here is the code

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

    }
}

}

Soundview
  • 43
  • 7

1 Answers1

0

Try this:

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();
JWP
  • 6,672
  • 3
  • 50
  • 74