Let's say I have a database with 2 tables : User(Id, Name, PetId,...) and Pet(Id, Name, Color,...) and this class :
class UserPet
{
// User table, generated in dbml
public User User {get;}
// Pet table, generated in dbml
public Pet Pet {get;}
public UserPet(User user, Pet pet)
{
User = user;
Pet = pet;
}
[...]
}
I'm trying to make a link to sql method with a filter like
public UserPet[] Get(Expression<Func<UserPet, bool>> criteria)
{
[...]
// System.NotSupportedException: 'The member 'User' has not supported translation to sql'
return (from user in context.User
join pet in context.Pet on usr.PetId equal pet.Id
--> select new UserPet(user, pet).Where(criteria).ToArray()
}
So that, for instance, I can make query with dynamic filtering:
Get(userPet => userPet.Pet.Color == "Red" && userPet.User.Name == "Dave")
Here, the criteria is an object containing 2 tables and I am struggling to use it in the linq to sql method. Any idea ? How to tell Linq To SQL that the properties of UserPet are the tables that were generated in the dbml ?
Thanks !