0

I have the following line of code:

protected Expression<Predicate<DuplicateCheck>> Name= x => x.Name == "smith";

when I add a .ToLower()

protected Expression<Predicate<DuplicateCheck>> Name= x => x.Name.ToLower() == "smith";

to try to generalize the query I get the error

System.Reflection.TargetException: 'Non-static method requires a target.'

Is this not available to use in this way?

Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56
dstewart101
  • 1,084
  • 1
  • 16
  • 38
  • How are you using `Name`? What is `Predicate<>`? Reflection is not involved in the definition of `Name` so the library or system you are using it with must be trying to parse the `ExpressionLambda` and doesn't handle complicated expressions. What library are you using? – NetMage Feb 07 '20 at 20:36

1 Answers1

0

System.Reflection.TargetException: 'Non-static method requires a target.'

Normally it happens when the target is null, So you need to check it first like below.

x => x != null && x.Name != null && x.Name.ToLower() == "smith"
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56