0

i do a linq query:

        var parcels = (from parcel in Db.Parcels
                                where
                                    (parcel.Neighbors.Count(neig =>
                                        {
                                            var neigType1 = neig.Neighbors as NeigType1;
                                            var neigType2 = neig.Neighbors as NeigType2;
                                            var result = false;
                                            if (neigType1 != null)
                                            {
                                                 result = neigType1.Name.Contains(NeigTextBox.Text);
                                            }

                                            if (neigType2 != null)
                                            {
                                               result = кадастроваяОрганизация.Name.Contains(NeigTextBox.Text);
                                            }
                                            return result;
                                        }) > 0)
                                select parcel).ToList();

But in line (parcel.Neighbors.Count(neig => i get an error:

A lambda expression with a statement body cannot be converted to an expression tree

Google says that it because i don't using => operator. But where i gonne put it?

Kliver Max
  • 5,107
  • 22
  • 95
  • 148

1 Answers1

1

Try this solution:

var parcels = Db.Parcels
    .Where(p => p.Neighbors.Count(neig =>
        {
            .....
            return result;
        }) > 0)
    .ToList();
alexmac
  • 19,087
  • 7
  • 58
  • 69
  • Will this not throw the same error? You still have a lambda expression with a statement body... – Chris Dec 19 '13 at 11:00