Search code examples
c#visual-studio-lightswitchlightswitch-2012

Using Computed Field in LightSwitch Query


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 ?


Solution

  • 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 !