Linq to SQL query filter with Lightswitch computed property

186 views Asked by At

With the help/suggestions I received in a previous question I asked, I managed to narrow my problem down to a computed property.

Here's the query filtering that fails:

query = query.Where(a => a.collection.Any(b => b.Name.StartsWith(c)));

Everything in there seems to work fine but Name causes the query to fail. Name is a computed property of b and when I replace that by a standard property, the query works.

I do not understand what that implies in the sql so I can't figure out how to fix/replace that so I can filter by that property. If anyone could explain what's going wrong behind that query it'd be appreciated.

2

There are 2 answers

4
Matt Thalman On BEST ANSWER

Computed properties are not defined in the underlying database and so you can't reference them in your queries.

2
Greg On

You should be able to do your goal, with the following:

var start = "Joh";
var query = content.Where(entity => 
                  entity.ExampleCollection.Exist(obj => 
                  obj.Name.StartsWith(start));

That will filter based on if it Exist within the collection and meets your start criteria.