I'm pretty sure the answer to this is "you can't do that" or "No, no, you misunderstand...", but:
I have a linq class, thing, which will happily execute this:
var thingsWithAandB = from t in db.things
where t.propA.HasValue && t.propB.HasValue
select t;
But I do this a lot, and so I want:
partial class thing
{
public bool hasAandB
{
get
{
return propA.HasValue && propB.HasValue;
}
}
}
and then:
var thingsWithAandB = from t in db.things where t.hasAandB select t;
But of course, when I do this, I get "Can't translate that into SQL" errors. And I understand that this is because calling methods in the middle of SQL queries isn't possible, since my code and the database are separate.
What's the way to do this? Is it impossible?
It is perfectly possible. Damien Guard (damieng.com) has a sample on his blog showing how to do that.
http://damieng.com/blog/2009/06/24/client-side-properties-and-any-remote-linq-provider
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With