Question: I'm newbie to linq to sql, just trying to understand what type of queries I can handle with linq.

Here is my database scheme,

![enter image description here](https://i.stack.imgur.com/K0Bi5.png)

I want to get all customers of a specific user and this is what I've done,

```
var userId = 4;
var companies = from c in db.Company
                where c.UserId == userId
                select c.Id;

var costumers = from c in db.Customers
                where companies.Contains(c.CompanyId)
                select c;

```

I'm just wondering whether it's a nice approach and is there any better method to handle this type of queries?

Answer: 
This example print `update` end finish execution.

```
public static void main(String[] args){
    //scheduler executor is a lot more sophisticated solution
    final ScheduledExecutorService sheduler = Executors.newScheduledThreadPool(1);
    class MyO extends Observable {
        public void trackChanged(){
            setChanged(); //this method is protected in super class
        }
    };
    //must be final because it used in nested class
    final MyO o = new MyO();
    o.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            //your processing here
            System.out.println("update");
            sheduler.shutdown();
        }
    });
    sheduler.schedule(new Runnable() {
        @Override
        public void run() {
            o.trackChanged();
            o.notifyObservers();
        }
    }, 3, TimeUnit.SECONDS); //set any timout
}

```
Here is a reusable OneShotTimer.

```java
    new OneShotTimer(3, () -> setChange());

```

```java
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class OneShotTimer
{

    final ScheduledExecutorService sheduler = Executors.newScheduledThreadPool(1);

    /// Call [callback] after [duration] seconds.
    public OneShotTimer(int duration, OneShotCallback callback)
    {
        sheduler.schedule(() -> _callback(callback), duration, TimeUnit.SECONDS);
    }

    void _callback(OneShotCallback callback)
    {
        sheduler.shutdown();
        callback.callback();
    }

    public interface OneShotCallback
    {
        void callback();
    }

}

```