0

Lets say I have a simple table of Customer with Field DayOfBirth and a computed field 'Age' Now I want to Search the table using Age.

I pass Age as parameter to the query so the first thing that came to my mind was :

                    query = from c in query
                    where (DateTime.Now - c.DateOfBirth).Days / 360 == Age.Value
                    select c;

but this of course wont work as the data provider wouldn't know how to execute ".Days"

so what is the proper way to do this ?

Stacker
  • 8,157
  • 18
  • 73
  • 135

2 Answers2

1

A solution would be adding non-Computed field inside the table and on adding new records event I just Compute the age and save it with the database so I can search by it later !

but I`m sure there should be better idea !

Stacker
  • 8,157
  • 18
  • 73
  • 135
0

There are ways of getting around the .Days part, but you'll have the same problem with the Age, property, except there won't be a way around that one. Computed properties only exist in LightSwitch itself, so once again the data provider isn't going to be able to use them.

Stacker's suggestion of adding a non-computed property & storing the calculated value in the database is the way I would do it (if I wasn't using a RIA Service, which is the way I actually handle these situations).

Yann Duran
  • 3,842
  • 1
  • 24
  • 24