(sender as TextBox).Text with EF strange error RRS feed

  • Question

  • hi ,

    i have this code

     var q = from per in dc.PersonSet
                    where per.FirstName.Contains((sender as TextBox).Text) ||
                    per.LastName.Contains((sender as TextBox).Text)
                    select per;
            personViewSource.Source = q.ToList();

    when it run i get this exception:

    "Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context."

    this exception gos away if i saved the (sender as TextBox).Text in a variable and used the variable in the quarry , like this

    var something = (sender as TextBox).Text;
            var q = from per in dc.PersonSet
                    where per.FirstName.Contains(something) ||
                    select per;
            personViewSource.Source = q.ToList();

    why is that ?

    Friday, August 30, 2013 6:19 PM