Frage

I'm trying to use expression tree in my linq to sql queries. and i use EF5

i wrote a method like this:

    private Expression<Func<Tbl1, bool>> Expr1()
    {              
        return tbl1 => tbl1.FSystemCode == (int)comboBoxSystemCode.SelectedValue;
    }

and my query is:

    private object bindingSourceTbl1_DataSourceBinding(object sender, EventArgs e)
   {
        using (SampleDbEntities dbo = new SampleDbEntities())
        {

           return dbo.Tbl1.Join(dbo.Tbl2, x => x.Id, y => y.Tbl1Id, (x, y) => new { Tbl1 = x, Tbl2 = y }).Where(this.Expr1()).Where(a => a.Tbl2.Tbl6Id == (int)comboBoxTbl6.SelectedValue).Select(a => a.Tbl1).ToList();
        }
    }

but fails at runtime for this .Where(this.Expr1())

Please help me to write correct code.

War es hilfreich?

Lösung

I Solved my problem by this change and this work for me:

private object bindingSourceTbl1_DataSourceBinding(object sender, EventArgs e)
{
    using (SampleDbEntities dbo = new SampleDbEntities())
    {

       return dbo.Tbl1.Join(dbo.Tbl2, x => x.Id, y => y.Tbl1Id, (x, y) => new { Tbl1 = x, Tbl2 = y }).Where(a => a.Tbl2.Tbl6Id == (int)comboBoxTbl6.SelectedValue).Select(a => a.Tbl1).Where(Expr1()).ToList();
    }
}

i think this must be true.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top