I have a D
object created from the automatic mapping of the D
table. I added the following property to it in a partial class.
public Address PhysicalAddress
{
get { return this.Addresses.FirstOrDefault(a => a.AddrType == "PHY"); }
}
This works fine on it's own.
I'd like to write the following linq query on it:
var result = from d in _db.D
where d.PhysicalAddress.State == addr.State
select d;
Which doesn't work. It throws a NotSupportedException
when I try to iterate over result
.
However, the following does work:
var result = from d in _db.D
where d.Addresses.Single(dAddr => dAddr.AddrType == "PHY").State == addr.State
select d;
Why does Linq to Sql work this way? Is there a way to re-write my property so that it will work?