Hello,
Let's say I have two tables (Address
and Phone
) in sql which have one-to-one relationship. I have created corresponding linq to sql classes and changed the association to OneToOne
I want to retrieve both objects by filtering child object. e.g I have the following query which works fine:
var n = db.Addresses.Where(t => t.Phone.Number == 100);
Is there any way I can make the following work:
var n = db.Addresses.Where(t => t.Phone == new Phone(100));
The Phone
class constructor above initializes the Number
property. As I can see the query that is issued contains a clause which filters Phones table by id (primary key) but the number clause in not included.
If I set Number
as primary key in visual studio then it is included in the where clause but the search still does not return anything as the parameter value for id is 0. Even if it worked it is not a solution as Number
should not be a primary key.