Question: I'm accessing a database column where a phone number is stored as a varchar in the format +a-b:c where a = country code, b = phone number and c = extension. E.g. +44-07700123456:123

So I have a type that handles serialization along the lines of:

```
public struct PhoneNumber {
  public PhoneNumber(string val) {  /*...*/ }
  public override string ToString() { /*...*/ }
  public static PhoneNumber TryParse(string val) { /*...*/ }
}

```

and a POCO:

```
public class Customer {
  public PhoneNumber? HomePhone;
}

```

Then in my data access code some Linq along the lines of:

```
public IQueryable<Customers> GetCustomers() {
  var customers = (from c in DataContext.Customers
  select new Customer {
    HomePhone = PhoneNumber.TryParse(c.HomePhone)
  });
  return customers;
}

```

So far so good, this all works fine when retrieving records from the database, but my problem is I can't perform a Linq query on the result like:

```
GetCustomers().Where(c => c != null && c.HomePhone.Value.ToString().Contains("123"));

```

I get a an error "Method 'System.Nullable`1[PhoneNumber] TryParse(System.String)' has no supported translation to SQL". Now I know I can perform the phone number search in GetCustomers() but this is not ideal.

Is there a way I can let Linq know how to translate my linq to sql? So that I can I do something like GetCustomers().Where(c => c.HomePhone.Value.ToString().Contains("123")) ?

P.S. Not sure on the title of this one, any alternatives are welcome.

Answer: 
Run the same query prefixed with EXPLAIN and add the output to your question - this will show what indexes you are using and the number of rows being analyzed.

You can see from your explain that no indexes are being used, and its having to look at thousands of rows to get your result. Try adding an index on the columns used to perform the join, e.g. nickname and stake:

```
ALTER TABLE masters_tp ADD INDEX(nickname),ADD INDEX(stake);
ALTER TABLE masters_cp ADD INDEX(nickname),ADD INDEX(stake);

```

(I've assumed the columns might have duplicated values, if not, use UNIQUE rather than INDEX). See the [MySQL manual](http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html) for more information.
It is simple query. I think everything is ok with it. You can try add indexes on 'stake' fields or make limit lower.